#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void Connect(int sockfd, const struct sockaddr_in *addr, socklen_t addrlen) {
  if (connect(sockfd, (struct sockaddr *)addr, addrlen) < 0)
    do {
      strerror(errno);
      puts("\n");
      err_quit("connect error");
    } while (1);
}


x86 assembly (clang, -O0):
<Connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
jge    11aa <Connect+0x6a>
jmp    1170 <Connect+0x30>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe71(%rip),%rdi
call   1040 <err_quit@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1170 <Connect+0x30>
jmp    11a5 <Connect+0x65>
jmp    11aa <Connect+0x6a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Connect>:
push   %r15
push   %r14
push   %rbx
call   1050 <connect@plt>
test   %rax,%rax
js     1155 <Connect+0x15>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e84(%rip),%r15
lea    0xe9d(%rip),%r14
lea    0xe98(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
call   1060 <strerror@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <err_quit@plt>
jmp    1170 <Connect+0x30>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [14 x i8] c"connect error\00"
define void @Connect(i32 %0, %struct.sockaddr_in* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%9 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%10 = load i32, i32* %6
%11 = call i64 @connect(i32 %7, %struct.sockaddr* %9, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %3
br label %14
14: ; preds = %19, %13
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @err_quit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %14
br i1 true, label %14, label %20
20: ; preds = %19
br label %21
21: ; preds = %20, %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [14 x i8] c"connect error\00"
define void @Connect(i32 %0, %struct.sockaddr_in* %1, i32 %2) {
%4 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%5 = tail call i64 @connect(i32 %0, %struct.sockaddr* %4, i32 %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3, %7
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @err_quit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %7
12: ; preds = %3
ret void
}