#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct addrinfo {
  int dummy;
};

/* Variables and functions */
int amqp_lookup_host_address(char const *, int, struct addrinfo **);
int establish_connection(char const *, struct addrinfo *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int amqp_blocking_tcp_connect_to(const char *host_name, int port) {
  struct addrinfo *host_entries;
  int eai_error;
  if ((eai_error = amqp_lookup_host_address(host_name, port, &host_entries)) ==
      0) {
    int fd = establish_connection(host_name, host_entries);
    freeaddrinfo(host_entries);
    return fd;
  }
  return -1;
}


x86 assembly (clang, -O0):
<amqp_blocking_tcp_connect_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1040 <amqp_lookup_host_address@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    117f <amqp_blocking_tcp_connect_to+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <establish_connection@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <freeaddrinfo@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <amqp_blocking_tcp_connect_to+0x56>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amqp_blocking_tcp_connect_to>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rdx
call   1040 <amqp_lookup_host_address@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jne    115e <amqp_blocking_tcp_connect_to+0x2e>
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1030 <establish_connection@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   1050 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32 }
define i32 @amqp_blocking_tcp_connect_to(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @amqp_lookup_host_address(i8* %9, i32 %10, %struct.addrinfo** %6)
store i32 %11, i32* %7
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load %struct.addrinfo*, %struct.addrinfo** %6
%16 = call i32 @establish_connection(i8* %14, %struct.addrinfo* %15)
store i32 %16, i32* %8
%17 = load %struct.addrinfo*, %struct.addrinfo** %6
%18 = call i32 @freeaddrinfo(%struct.addrinfo* %17)
%19 = load i32, i32* %8
store i32 %19, i32* %3
br label %21
20: ; preds = %2
store i32 -1, i32* %3
br label %21
21: ; preds = %20, %13
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
define i32 @amqp_blocking_tcp_connect_to(i8* %0, i32 %1) {
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo** %3 to i8*
%5 = call i32 @amqp_lookup_host_address(i8* %0, i32 %1, %struct.addrinfo** %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load %struct.addrinfo*, %struct.addrinfo** %3
%9 = call i32 @establish_connection(i8* %0, %struct.addrinfo* %8)
%10 = load %struct.addrinfo*, %struct.addrinfo** %3
%11 = call i32 @freeaddrinfo(%struct.addrinfo* %10)
br label %12
12: ; preds = %2, %7
%13 = phi i32 [ %9, %7 ], [ -1, %2 ]
ret i32 %13
}