#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ so_linger;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_LINGER;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_SNDTIMEO;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc == 1)
    error("USAGE [program ip port]", 1);
  int cfd;
  struct sockaddr_in s_add;
  cfd = socket(AF_INET, SOCK_STREAM, 0);
  if (-1 == cfd)
    error("socket create failed!", -1);
  fprintf(stdout, "socket created!\n");
  bzero(&s_add, sizeof(struct sockaddr_in));
  s_add.sin_family = AF_INET;
  s_add.sin_addr.s_addr = inet_addr(argv[1]);
  s_add.sin_port = htons(atoi(argv[2]));
  struct timeval tv_timeout;
  tv_timeout.tv_sec = 2;
  tv_timeout.tv_usec = 0;
  struct linger {
    int l_onoff;
    int l_linger;
  };
  struct linger so_linger;
  so_linger.l_onoff = 1;
  so_linger.l_linger = 0;
  if (setsockopt(cfd, SOL_SOCKET, SO_SNDTIMEO, (void *)&tv_timeout,
                 sizeof(struct timeval)) < 0) {
    error("setsockopt SO_SNDTIMEO error!", -1);
  }
  if (setsockopt(cfd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv_timeout,
                 sizeof(struct timeval)) < 0) {
    error("setsockopt SO_RCVTIMEO error!", -1);
  }
  if (setsockopt(cfd, SOL_SOCKET, SO_LINGER, (void *)&so_linger,
                 sizeof(so_linger)) < 0) {
    error("setsockopt SO_LINGER error!", -1);
  }
  if (-1 ==
      connect(cfd, (struct sockaddr *)(&s_add), sizeof(struct sockaddr))) {
    error("connect failed!", -1);
  }
  fprintf(stdout, "connect ok!\n");
  close(cfd);
  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   $0x1,-0x8(%rbp)
jne    11d1 <main+0x31>
lea    0xe39(%rip),%rdi
mov    $0x1,%esi
call   1080 <error@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    120c <main+0x6c>
lea    0xe16(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
movl   $0x2,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    0x2d5e(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12be <main+0x11e>
lea    0xd8b(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    -0x14(%rbp),%edi
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
mov    0x2cef(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12fd <main+0x15d>
lea    0xd6a(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    -0x14(%rbp),%edi
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
mov    0x2cc0(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    133c <main+0x19c>
lea    0xd49(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    136d <main+0x1cd>
lea    0xd34(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jne    11c4 <main+0x24>
lea    0xe46(%rip),%rdi
mov    $0x1,%esi
call   1080 <error@plt>
mov    0x2e0d(%rip),%r12
mov    (%r12),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11f7 <main+0x57>
lea    0xe2b(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    0x2db2(%rip),%r15
mov    (%r15),%edi
lea    0xe26(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rsp,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
movl   $0x2,0x18(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x1,0x10(%rsp)
mov    0x2d7d(%rip),%r14
mov    (%r14),%esi
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
lea    0x18(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    1297 <main+0xf7>
lea    0xdb2(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    (%r14),%esi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
lea    0x18(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    12cb <main+0x12b>
lea    0xd9c(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    (%r14),%esi
mov    0x2cfb(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    12ff <main+0x15f>
lea    0xd86(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1324 <main+0x184>
lea    0xd7d(%rip),%rdi
mov    $0xffffffff,%esi
call   1080 <error@plt>
mov    (%r15),%edi
lea    0xd79(%rip),%rsi
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.linger = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"USAGE [program ip port]\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"socket create failed!\00"
@stdout = global i32 0
@.str.2 = [17 x i8] c"socket created!\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str.3 = [30 x i8] c"setsockopt SO_SNDTIMEO error!\00"
@SO_RCVTIMEO = global i32 0
@.str.4 = [30 x i8] c"setsockopt SO_RCVTIMEO error!\00"
@SO_LINGER = global i32 0
@.str.5 = [28 x i8] c"setsockopt SO_LINGER error!\00"
@.str.6 = [16 x i8] c"connect failed!\00"
@.str.7 = [13 x i8] c"connect ok!\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 %struct.timeval
%9 = alloca %struct.linger
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 1)
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %22
22: ; preds = %20, %14
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @inet_addr(i8* %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 2, i32* %40
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 0, i64* %41
%42 = getelementptr inbounds %struct.linger, %struct.linger* %9, i32 0, i32 0
store i32 1, i32* %42
%43 = getelementptr inbounds %struct.linger, %struct.linger* %9, i32 0, i32 1
store i32 0, i32* %43
%44 = load i32, i32* %6
%45 = load i32, i32* @SOL_SOCKET
%46 = load i32, i32* @SO_SNDTIMEO
%47 = bitcast %struct.timeval* %8 to i8*
%48 = call i64 @setsockopt(i32 %44, i32 %45, i32 %46, i8* %47, i32 16)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %22
%51 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 -1)
br label %52
52: ; preds = %50, %22
%53 = load i32, i32* %6
%54 = load i32, i32* @SOL_SOCKET
%55 = load i32, i32* @SO_RCVTIMEO
%56 = bitcast %struct.timeval* %8 to i8*
%57 = call i64 @setsockopt(i32 %53, i32 %54, i32 %55, i8* %56, i32 16)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 -1)
br label %61
61: ; preds = %59, %52
%62 = load i32, i32* %6
%63 = load i32, i32* @SOL_SOCKET
%64 = load i32, i32* @SO_LINGER
%65 = bitcast %struct.linger* %9 to i8*
%66 = call i64 @setsockopt(i32 %62, i32 %63, i32 %64, i8* %65, i32 8)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %61
%69 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %70
70: ; preds = %68, %61
%71 = load i32, i32* %6
%72 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%73 = call i32 @connect(i32 %71, %struct.sockaddr* %72, i32 4)
%74 = icmp eq i32 -1, %73
br i1 %74, label %75, label %77
75: ; preds = %70
%76 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 -1)
br label %77
77: ; preds = %75, %70
%78 = load i32, i32* @stdout
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%80 = load i32, i32* %6
%81 = call i32 @close(i32 %80)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.linger = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"USAGE [program ip port]\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"socket create failed!\00"
@stdout = global i32 0
@.str.2 = [17 x i8] c"socket created!\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str.3 = [30 x i8] c"setsockopt SO_SNDTIMEO error!\00"
@SO_RCVTIMEO = global i32 0
@.str.4 = [30 x i8] c"setsockopt SO_RCVTIMEO error!\00"
@SO_LINGER = global i32 0
@.str.5 = [28 x i8] c"setsockopt SO_LINGER error!\00"
@.str.6 = [16 x i8] c"connect failed!\00"
@.str.7 = [13 x i8] c"connect ok!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.timeval
%5 = alloca %struct.linger
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 1)
br label %9
9: ; preds = %7, %2
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%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 %17
15: ; preds = %9
%16 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %17
17: ; preds = %15, %9
%18 = load i32, i32* @stdout
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%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 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @inet_addr(i8* %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
%30 = tail call i32 @htons(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.timeval* %4 to i8*
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 2, i32* %33
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %34
%35 = bitcast %struct.linger* %5 to i8*
%36 = getelementptr inbounds %struct.linger, %struct.linger* %5, i64 0, i32 0
store i32 1, i32* %36
%37 = getelementptr inbounds %struct.linger, %struct.linger* %5, i64 0, i32 1
store i32 0, i32* %37
%38 = load i32, i32* @SOL_SOCKET
%39 = load i32, i32* @SO_SNDTIMEO
%40 = call i64 @setsockopt(i32 %13, i32 %38, i32 %39, i8* %32, i32 16)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %17
%43 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 -1)
br label %44
44: ; preds = %42, %17
%45 = load i32, i32* @SOL_SOCKET
%46 = load i32, i32* @SO_RCVTIMEO
%47 = call i64 @setsockopt(i32 %13, i32 %45, i32 %46, i8* %32, i32 16)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 -1)
br label %51
51: ; preds = %49, %44
%52 = load i32, i32* @SOL_SOCKET
%53 = load i32, i32* @SO_LINGER
%54 = call i64 @setsockopt(i32 %13, i32 %52, i32 %53, i8* %35, i32 8)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %58
58: ; preds = %56, %51
%59 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%60 = call i32 @connect(i32 %13, %struct.sockaddr* %59, i32 4)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 -1)
br label %64
64: ; preds = %62, %58
%65 = load i32, i32* @stdout
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%67 = call i32 @close(i32 %13)
ret i32 0
}