#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*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_FASTOPEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ htons(int const);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char const *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, int);
int send(int, char *, int, int /*<<< orphan*/);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int /*<<< orphan*/);
int client(const char *remoteip, const int remoteport, bool fastopen) {
  struct sockaddr_in serv_addr;
  char data[2048];
  int data_len = 2048;
  int sfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(remoteport);
  inet_pton(AF_INET, remoteip, &serv_addr.sin_addr);
  int err = 0;
  if (fastopen) {
    int len = sendto(sfd, data, data_len, MSG_FASTOPEN,
                     (struct sockaddr *)&serv_addr, sizeof(serv_addr));
    printf("sendto fastopen error: %s , len = %d\n", strerror(errno), len);
  } else {
    err = connect(sfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
    printf("connect error: %s , len = %d\n", strerror(errno), err);
    sleep(10);
    int len = send(sfd, data, data_len, 0);
    printf("send error: %s , len = %d\n", strerror(errno), len);
  }
  close(sfd);
  sleep(3);
  return 0;
}


x86 assembly (clang, -O0):
<client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x800,-0x824(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x828(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <inet_pton@plt>
movl   $0x0,-0x82c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1296 <client+0xe6>
mov    -0x828(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x824(%rbp),%edx
mov    0x2d89(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x830(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
mov    -0x830(%rbp),%edx
lea    0xd74(%rip),%rdi
call   1050 <printf@plt>
jmp    1320 <client+0x170>
mov    -0x828(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,-0x82c(%rbp)
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
mov    -0x82c(%rbp),%edx
lea    0xd58(%rip),%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
mov    -0x828(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x824(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x834(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
mov    -0x834(%rbp),%edx
lea    0xd29(%rip),%rdi
call   1050 <printf@plt>
mov    -0x828(%rbp),%edi
call   1070 <close@plt>
mov    $0x3,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r13
mov    0x2e18(%rip),%rbx
mov    (%rbx),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r14d
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1080 <inet_pton@plt>
test   %r15d,%r15d
je     1255 <client+0xa5>
mov    0x2dc1(%rip),%rax
mov    (%rax),%ecx
lea    0x10(%rsp),%rsi
mov    %rsp,%r8
mov    %r14d,%edi
mov    $0x800,%edx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,%ebx
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdad(%rip),%rdi
jmp    12b6 <client+0x106>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,%ebx
mov    0x2d5a(%rip),%rbp
mov    0x0(%rbp),%edi
call   10b0 <strerror@plt>
lea    0xda9(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <printf@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%edi
call   10b0 <strerror@plt>
lea    0xd8e(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <printf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0x3,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@MSG_FASTOPEN = global i32 0
@.str = [38 x i8] c"sendto fastopen error: %s , len = %d\0A\00"
@errno = global i32 0
@.str.1 = [30 x i8] c"connect error: %s , len = %d\0A\00"
@.str.2 = [27 x i8] c"send error: %s , len = %d\0A\00"
define i32 @client(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [2048 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 2048, i32* %9
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %10
%17 = bitcast %struct.sockaddr_in* %7 to i8*
%18 = call i32 @bzero(i8* %17, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* %5
%22 = call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = load i8*, i8** %4
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%27 = call i32 @inet_pton(i32 %24, i8* %25, i32* %26)
store i32 0, i32* %11
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %3
%31 = load i32, i32* %10
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%33 = load i32, i32* %9
%34 = load i32, i32* @MSG_FASTOPEN
%35 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%36 = call i32 @sendto(i32 %31, i8* %32, i32 %33, i32 %34, %struct.sockaddr* %35, i32 12)
store i32 %36, i32* %12
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = load i32, i32* %12
%40 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %38, i32 %39)
br label %58
41: ; preds = %3
%42 = load i32, i32* %10
%43 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%44 = call i32 @connect(i32 %42, %struct.sockaddr* %43, i32 12)
store i32 %44, i32* %11
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = load i32, i32* %11
%48 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %46, i32 %47)
%49 = call i32 @sleep(i32 10)
%50 = load i32, i32* %10
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %9
%53 = call i32 @send(i32 %50, i8* %51, i32 %52, i32 0)
store i32 %53, i32* %13
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = load i32, i32* %13
%57 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %55, i32 %56)
br label %58
58: ; preds = %41, %30
%59 = load i32, i32* %10
%60 = call i32 @close(i32 %59)
%61 = call i32 @sleep(i32 3)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@MSG_FASTOPEN = global i32 0
@.str = [38 x i8] c"sendto fastopen error: %s , len = %d\0A\00"
@errno = global i32 0
@.str.1 = [30 x i8] c"connect error: %s , len = %d\0A\00"
@.str.2 = [27 x i8] c"send error: %s , len = %d\0A\00"
define i32 @client(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca [2048 x i8]
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = call i32 @bzero(i8* %6, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 %1)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%18 = call i32 @inet_pton(i32 %16, i8* %0, i32* %17)
%19 = icmp eq i32 %2, 0
br i1 %19, label %27, label %20
20: ; preds = %3
%21 = load i32, i32* @MSG_FASTOPEN
%22 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%23 = call i32 @sendto(i32 %10, i8* %7, i32 2048, i32 %21, %struct.sockaddr* %22, i32 12)
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %23)
br label %38
27: ; preds = %3
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i32 @connect(i32 %10, %struct.sockaddr* %28, i32 12)
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %31, i32 %29)
%33 = call i32 @sleep(i32 10)
%34 = call i32 @send(i32 %10, i8* %7, i32 2048, i32 0)
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %36, i32 %34)
br label %38
38: ; preds = %27, %20
%39 = call i32 @close(i32 %10)
%40 = call i32 @sleep(i32 3)
ret i32 0
}