#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 /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void example_connect(int sock, struct addrinfo *ai) {
  if (connect(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
    perror("connect() failure: ");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<example_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1050 <connect@plt>
cmp    $0xffffffff,%eax
jne    1177 <example_connect+0x47>
lea    0xe9c(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<example_connect>:
push   %rax
mov    (%rsi),%edx
mov    0x4(%rsi),%esi
call   1050 <connect@plt>
cmp    $0xffffffff,%eax
je     1142 <example_connect+0x12>
pop    %rax
ret
lea    0xeb7(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
@.str = [20 x i8] c"connect() failure: \00"
@EXIT_FAILURE = global i32 0
define void @example_connect(i32 %0, %struct.addrinfo* %1) {
%3 = alloca i32
%4 = alloca %struct.addrinfo*
store i32 %0, i32* %3
store %struct.addrinfo* %1, %struct.addrinfo** %4
%5 = load i32, i32* %3
%6 = load %struct.addrinfo*, %struct.addrinfo** %4
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
%8 = load i32, i32* %7
%9 = load %struct.addrinfo*, %struct.addrinfo** %4
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @connect(i32 %5, i32 %8, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@.str = [20 x i8] c"connect() failure: \00"
@EXIT_FAILURE = global i32 0
define void @example_connect(i32 %0, %struct.addrinfo* nocapture %1) {
%3 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 @connect(i32 %0, i32 %4, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
ret void
}