#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ ret;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ print_turn(char *);
int read(int, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void *run_listen(void *arg) {
  char **argv = (char **)arg;
  int sockfd;
  int len;
  struct sockaddr_in address;
  int ret;
  const int LINE_LEN = 512;
  char line[LINE_LEN];
  sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = inet_addr(argv[1]);
  address.sin_port = htons(2220);
  len = sizeof(address);
  ret = connect(sockfd, (struct sockaddr *)&address, len);
  if (ret == -1) {
    exit(1);
  }
  sprintf(line, "L%s", argv[2]);
  write(sockfd, line, strlen(line));
  read(sockfd, &ret, sizeof(ret));
  sprintf(line, "result from server = %d", ret);
  print_turn(line);
  while ((len = read(sockfd, line, LINE_LEN)) > 0) {
    line[len - 1] = 0;
    print_turn(line);
  };
  close(sockfd);
  return (void *)0;
}


x86 assembly (clang, -O0):
<run_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x200,-0x30(%rbp)
mov    %rsp,%rax
mov    %rax,-0x38(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x8ac,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10b0 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    124e <run_listen+0x9e>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    -0x240(%rbp),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x244(%rbp)
lea    -0x240(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x244(%rbp),%edi
mov    %eax,%edx
lea    -0x240(%rbp),%rsi
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    -0x2c(%rbp),%edx
lea    -0x240(%rbp),%rdi
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x240(%rbp),%rdi
call   10c0 <print_turn@plt>
mov    -0x14(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    130e <run_listen+0x15e>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x240(%rbp,%rax,1)
lea    -0x240(%rbp),%rdi
call   10c0 <print_turn@plt>
jmp    12cb <run_listen+0x11b>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_listen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
mov    0x2e1e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r14),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x8ac,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     12df <run_listen+0x12f>
mov    0x10(%r14),%rdx
lea    0xdd1(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1070 <read@plt>
mov    0xc(%rsp),%edx
lea    0xd94(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   10c0 <print_turn@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1070 <read@plt>
test   %eax,%eax
jle    12c5 <run_listen+0x115>
lea    0x20(%rsp),%rbx
nopl   0x0(%rax)
add    $0xffffffff,%eax
movb   $0x0,0x20(%rsp,%rax,1)
mov    %rbx,%rdi
call   10c0 <print_turn@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1070 <read@plt>
test   %eax,%eax
jg     12a0 <run_listen+0xf0>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r15,%rsp
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [4 x i8] c"L%s\00"
@.str.1 = [24 x i8] c"result from server = %d\00"
define i8* @run_listen(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = bitcast i8* %10 to i8**
store i8** %11, i8*** %3
store i32 512, i32* %8
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %9
%13 = alloca i8, i64 512
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = load i32, i32* @IPPROTO_TCP
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i8**, i8*** %3
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @inet_addr(i8* %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = call i32 @htons(i32 2220)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %26, i32* %27
store i32 12, i32* %5
%28 = load i32, i32* %4
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = load i32, i32* %5
%31 = call i32 @connect(i32 %28, %struct.sockaddr* %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %1
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %1
%37 = load i8**, i8*** %3
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %4
%42 = call i32 @strlen(i8* %13)
%43 = call i32 @write(i32 %41, i8* %13, i32 %42)
%44 = load i32, i32* %4
%45 = call i32 (i32, ...) @read(i32 %44, i32* %7, i64 4)
%46 = load i32, i32* %7
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = call i32 @print_turn(i8* %13)
br label %49
49: ; preds = %53, %36
%50 = load i32, i32* %4
%51 = call i32 (i32, ...) @read(i32 %50, i8* %13, i32 512)
store i32 %51, i32* %5
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i32, i32* %5
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %13, i64 %56
store i8 0, i8* %57
%58 = call i32 @print_turn(i8* %13)
br label %49
59: ; preds = %49
%60 = load i32, i32* %4
%61 = call i32 @close(i32 %60)
%62 = load i8*, i8** %9
ret i8* null
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [4 x i8] c"L%s\00"
@.str.1 = [24 x i8] c"result from server = %d\00"
define noalias i8* @run_listen(i8* nocapture %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i8* @llvm.stacksave()
%7 = alloca [512 x i8]
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = tail call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds i8, i8* %0, i64 8
%16 = bitcast i8* %15 to i8**
%17 = load i8*, i8** %16
%18 = tail call i32 @inet_addr(i8* %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 2220)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%23 = call i32 @connect(i32 %12, %struct.sockaddr* %22, i32 12)
store i32 %23, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %1
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %1
%28 = getelementptr inbounds i8, i8* %0, i64 16
%29 = bitcast i8* %28 to i8**
%30 = load i8*, i8** %29
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @strlen(i8* %8)
%33 = call i32 @write(i32 %12, i8* %8, i32 %32)
%34 = call i32 (i32, ...) @read(i32 %12, i32* %3, i64 4)
%35 = load i32, i32* %3
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = call i32 @print_turn(i8* %8)
%38 = call i32 (i32, ...) @read(i32 %12, i8* %8, i32 512)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %27, %40
%41 = phi i32 [ %46, %40 ], [ %38, %27 ]
%42 = add nsw i32 %41, -1
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %43
store i8 0, i8* %44
%45 = call i32 @print_turn(i8* %8)
%46 = call i32 (i32, ...) @read(i32 %12, i8* %8, i32 512)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %40, label %48
48: ; preds = %40, %27
%49 = call i32 @close(i32 %12)
ret i8* null
}