#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 */
typedef int /*<<< orphan*/ svaddr;
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*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ str_cli(int);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in svaddr;
  int ret;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <IP address>\n", argv[0]);
    return -1;
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  memset(&svaddr, 0, sizeof(svaddr));
  svaddr.sin_family = AF_INET;
  svaddr.sin_port = htons(10000);
  ret = inet_pton(AF_INET, argv[1], &svaddr.sin_addr);
  if (ret != 1) {
    fprintf(stderr, "inet_pton() for %s failed: %s\n", argv[1],
            strerror(errno));
    close(sockfd);
    return -1;
  }
  ret = connect(sockfd, (struct sockaddr *)&svaddr, sizeof(svaddr));
  if (ret == -1) {
    fprintf(stderr, "connect() failed: %s\n", strerror(errno));
    close(sockfd);
    return -1;
  }
  str_cli(sockfd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130f <main+0x17f>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2710,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1298 <main+0x108>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130f <main+0x17f>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12f8 <main+0x168>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130f <main+0x17f>
mov    -0x14(%rbp),%edi
call   1060 <str_cli@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    122e <main+0x9e>
mov    0x2e3b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    $0x2710,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x0(%rbp),%edi
mov    0x8(%rbx),%rsi
mov    %r15,%rdx
call   1080 <inet_pton@plt>
cmp    $0x1,%eax
jne    124a <main+0xba>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     127d <main+0xed>
mov    %r14d,%edi
call   1060 <str_cli@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    12b4 <main+0x124>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdbf(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12af <main+0x11f>
mov    0x2d87(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdac(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a7 <main+0x117>
mov    0x2d54(%rip),%rax
mov    (%rax),%ebx
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <IP address>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"inet_pton() for %s failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"connect() failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
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 %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %62
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 10000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%31 = call i32 @inet_pton(i32 %26, i8* %29, i32* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %44
34: ; preds = %17
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %40)
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
store i32 -1, i32* %3
br label %62
44: ; preds = %17
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%47 = call i32 @connect(i32 %45, %struct.sockaddr* %46, i32 12)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %57
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
store i32 -1, i32* %3
br label %62
57: ; preds = %44
%58 = load i32, i32* %6
%59 = call i32 @str_cli(i32 %58)
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
store i32 0, i32* %3
br label %62
62: ; preds = %57, %50, %34, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <IP address>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"inet_pton() for %s failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"connect() failed: %s\0A\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 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %45
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 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 10000)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%23 = call i32 @inet_pton(i32 %19, i8* %21, i32* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %32, label %25
25: ; preds = %10
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %20
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
%31 = call i32 @close(i32 %13)
br label %45
32: ; preds = %10
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i32 @connect(i32 %13, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = call i32 @close(i32 %13)
br label %45
42: ; preds = %32
%43 = call i32 @str_cli(i32 %13)
%44 = call i32 @close(i32 %13)
br label %45
45: ; preds = %42, %36, %25, %6
%46 = phi i32 [ -1, %6 ], [ -1, %25 ], [ -1, %36 ], [ 0, %42 ]
ret i32 %46
}