#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 */
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;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ echo_cli(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int sock;
  if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    do {
      perror("socket");
      exit(EXIT_FAILURE);
    } while (0);
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(5188);
  servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
    do {
      perror("connect");
      exit(EXIT_FAILURE);
    } while (0);
  echo_cli(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11da <main+0x5a>
jmp    11c0 <main+0x40>
lea    0xe39(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1444,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xdfd(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    124c <main+0xcc>
jmp    1232 <main+0xb2>
lea    0xdd8(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
call   1070 <echo_cli@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1211 <main+0x91>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x1444,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xe24(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     121a <main+0x9a>
mov    %ebx,%edi
call   1070 <echo_cli@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde8(%rip),%rdi
jmp    1221 <main+0xa1>
lea    0xdf0(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [8 x i8] c"connect\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = load i32, i32* @IPPROTO_TCP
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
br label %10
10: ; preds = %9
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %0
%16 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 5188)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i64 @connect(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %15
br label %29
29: ; preds = %28
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; No predecessors!
br label %34
34: ; preds = %33, %15
%35 = load i32, i32* %2
%36 = call i32 @echo_cli(i32 %35)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [8 x i8] c"connect\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = load i32, i32* @PF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = load i32, i32* @IPPROTO_TCP
%5 = tail call i32 @socket(i32 %2, i32 %3, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = bitcast %struct.sockaddr_in* %1 to i8*
%13 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 5188)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i64 @connect(i32 %5, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %11
%24 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %11
%28 = call i32 @echo_cli(i32 %5)
ret i32 0
}