#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 /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ client_log(char *);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void client_init(int *sockfd, struct sockaddr_in *server_addr,
                 const char *server_ip, int port) {
  if ((*sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "create socket error");
    exit(1);
  }
  bzero(server_addr, sizeof(*server_addr));
  server_addr->sin_family = AF_INET;
  server_addr->sin_port = htons(port);
  if (inet_pton(AF_INET, server_ip, &(server_addr->sin_addr)) <= 0) {
    fprintf(stderr, "inet_pton error for %s", server_ip);
    exit(1);
  }
  if (connect(*sockfd, (struct sockaddr *)server_addr, sizeof(*server_addr)) <
      0) {
    fprintf(stderr, "connect error\n");
    exit(1);
  }
  client_log("Connect to Server successful!");
}


x86 assembly (clang, -O0):
<client_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    11e0 <client_init+0x60>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <inet_pton@plt>
cmp    $0x0,%rax
jg     1254 <client_init+0xd4>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1293 <client_init+0x113>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xda0(%rip),%rdi
call   1030 <client_log@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e4e(%rip),%r12
mov    (%r12),%edi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,(%r15)
test   %eax,%eax
js     1210 <client_init+0x90>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rbx)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rbx)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <inet_pton@plt>
test   %rax,%rax
jle    1222 <client_init+0xa2>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     1246 <client_init+0xc6>
lea    0xe37(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <client_log@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
jmp    1256 <client_init+0xd6>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"create socket error\00"
@.str.1 = [23 x i8] c"inet_pton error for %s\00"
@.str.2 = [15 x i8] c"connect error\0A\00"
@.str.3 = [30 x i8] c"Connect to Server successful!\00"
define void @client_init(i32* %0, %struct.sockaddr_in* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca %struct.sockaddr_in*
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %5
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32*, i32** %5
store i32 %11, i32* %12
%13 = icmp slt i32 %11, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %4
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%20 = call i32 @bzero(%struct.sockaddr_in* %19, i32 12)
%21 = load i32, i32* @AF_INET
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 2
store i32 %21, i32* %23
%24 = load i32, i32* %8
%25 = call i32 @htons(i32 %24)
%26 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %26, i32 0, i32 1
store i32 %25, i32* %27
%28 = load i32, i32* @AF_INET
%29 = load i8*, i8** %7
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 0
%32 = call i64 @inet_pton(i32 %28, i8* %29, i32* %31)
%33 = icmp sle i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %18
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %7
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %18
%40 = load i32*, i32** %5
%41 = load i32, i32* %40
%42 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%43 = bitcast %struct.sockaddr_in* %42 to %struct.sockaddr*
%44 = call i64 @connect(i32 %41, %struct.sockaddr* %43, i32 12)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %39
%51 = call i32 @client_log(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"create socket error\00"
@.str.1 = [23 x i8] c"inet_pton error for %s\00"
@.str.2 = [15 x i8] c"connect error\0A\00"
@.str.3 = [30 x i8] c"Connect to Server successful!\00"
define void @client_init(i32* nocapture %0, %struct.sockaddr_in* %1, i8* %2, i32 %3) {
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %0
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = tail call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 %3)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%21 = tail call i64 @inet_pton(i32 %19, i8* %2, i32* %20)
%22 = icmp slt i64 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %13
%28 = load i32, i32* %0
%29 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%30 = tail call i64 @connect(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = tail call i32 @client_log(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
ret void
}