#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ to_server_addr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ 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 connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int Client_Init(char *host, int port) {
  int flag = 1, client_fd;
  struct sockaddr_in to_server_addr;
  if ((client_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    return (-1);
  }
  memset((char *)&to_server_addr, 0, sizeof(to_server_addr));
  to_server_addr.sin_family = AF_INET;
  to_server_addr.sin_port = htons(port);
  to_server_addr.sin_addr.s_addr = inet_addr(host);
  if (connect(client_fd, (struct sockaddr *)&to_server_addr,
              sizeof(struct sockaddr)) == -1) {
    printf("can't connect backend server\n");
    return (-1);
  }
  return client_fd;
}


x86 assembly (clang, -O0):
<Client_Init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11a7 <Client_Init+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <Client_Init+0xb2>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    120c <Client_Init+0xac>
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <Client_Init+0xb2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Client_Init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e70(%rip),%r12
mov    (%r12),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ebx
je     11f1 <Client_Init+0x91>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
call   1060 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cmp    $0xffffffff,%ecx
jne    11f1 <Client_Init+0x91>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [30 x i8] c"can't connect backend server\0A\00"
define i32 @Client_Init(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %6
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %34
14: ; preds = %2
%15 = bitcast %struct.sockaddr_in* %8 to i8*
%16 = call i32 @memset(i8* %15, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* %5
%20 = call i32 @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i8*, i8** %4
%23 = call i32 @inet_addr(i8* %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %7
%27 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%28 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %14
%31 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
32: ; preds = %14
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %34
34: ; preds = %32, %30, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@str = [29 x i8] c"can't connect backend server\00"
define i32 @Client_Init(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = call i32 @memset(i8* %4, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @htons(i32 %1)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* %0)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @connect(i32 %7, %struct.sockaddr* %17, i32 4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %9, %2, %20
%23 = phi i32 [ -1, %20 ], [ -1, %2 ], [ %7, %9 ]
ret i32 %23
}