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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_and_recv(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char buf[1024];
  int connfd;
  struct sockaddr_in servaddr;
  if (argc != 2) {
    printf("Input server ip !\n");
    exit(EXIT_FAILURE);
  }
  if ((connfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    printf("Socket Error...\n", errno);
    exit(EXIT_FAILURE);
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(29876);
  inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
  if (connect(connfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("Connect error..\n");
    exit(EXIT_FAILURE);
  }
  send_and_recv(connfd);
  close(connfd);
  printf("Exit\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cf <main+0x3f>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x414(%rbp)
cmp    $0xffffffff,%eax
jne    121c <main+0x8c>
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    $0x74b4,%edi
call   1030 <htons@plt>
mov    %eax,-0x41c(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x420(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    -0x414(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    12a6 <main+0x116>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x414(%rbp),%edi
call   1070 <send_and_recv@plt>
mov    -0x414(%rbp),%edi
call   1050 <close@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    123d <main+0xad>
mov    %rsi,%r14
mov    0x2e3a(%rip),%r12
mov    (%r12),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xb6>
mov    %eax,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    $0x74b4,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r12),%edi
mov    0x8(%r14),%rsi
mov    %r15,%rdx
call   1060 <inet_pton@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     124f <main+0xbf>
mov    %ebx,%edi
call   1070 <send_and_recv@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xde1(%rip),%rdi
jmp    1256 <main+0xc6>
lea    0xdc8(%rip),%rdi
jmp    1256 <main+0xc6>
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@errno = global i32 0
@str = [5 x i8] c"Exit\00"
@str.4 = [16 x i8] c"Connect error..\00"
@str.5 = [16 x i8] c"Socket Error...\00"
@str.6 = [18 x i8] c"Input server ip !\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 29876)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%29 = call i32 @inet_pton(i32 %25, i8* %27, i32* %28)
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i64 @connect(i32 %13, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %19
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %19
%38 = call i32 @send_and_recv(i32 %13)
%39 = call i32 @close(i32 %13)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}