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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  char buffer[500 + 1];
  int len, mysocket;
  struct sockaddr_in dest;
  mysocket = socket(AF_INET, SOCK_STREAM, 0);
  memset(&dest, 0, sizeof(dest));
  dest.sin_family = AF_INET;
  dest.sin_addr.s_addr = inet_addr("128.10.12.141");
  dest.sin_port = htons(3111);
  connect(mysocket, (struct sockaddr *)&dest, sizeof(struct sockaddr));
  char *msg = "3\n";
  char *msg2 = "45,46\n";
  char *msg3 = "45,47\n";
  char *msg4 = "1\n";
  send(mysocket, msg, strlen(msg), 0);
  while (1) {
    len = recv(mysocket, buffer, 500, 0);
    if (len > 0) {
      break;
    }
  }
  buffer[len] = '\0';
  printf("Received: %s (%d bytes).\n", buffer, len);
  send(mysocket, msg2, strlen(msg2), 0);
  send(mysocket, msg3, strlen(msg3), 0);
  send(mysocket, msg4, strlen(msg3), 0);
  close(mysocket);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x218(%rbp)
lea    -0x228(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x220(%rbp)
lea    0xdff(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x224(%rbp)
mov    $0xc27,%edi
call   1050 <htons@plt>
mov    %eax,-0x228(%rbp)
mov    -0x218(%rbp),%edi
lea    -0x228(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
lea    0xdd4(%rip),%rax
mov    %rax,-0x230(%rbp)
lea    0xdc9(%rip),%rax
mov    %rax,-0x238(%rbp)
lea    0xdc2(%rip),%rax
mov    %rax,-0x240(%rbp)
lea    0xdbb(%rip),%rax
mov    %rax,-0x248(%rbp)
mov    -0x218(%rbp),%eax
mov    %eax,-0x254(%rbp)
mov    -0x230(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x254(%rbp),%edi
mov    -0x250(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x218(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x1f4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jle    12d8 <main+0x138>
jmp    12dd <main+0x13d>
jmp    12a7 <main+0x107>
movslq -0x214(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rsi
mov    -0x214(%rbp),%edx
lea    0xd22(%rip),%rdi
call   1070 <printf@plt>
mov    -0x218(%rbp),%eax
mov    %eax,-0x284(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,-0x280(%rbp)
mov    -0x238(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x284(%rbp),%edi
mov    -0x280(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x218(%rbp),%eax
mov    %eax,-0x274(%rbp)
mov    -0x240(%rbp),%rax
mov    %rax,-0x270(%rbp)
mov    -0x240(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x274(%rbp),%edi
mov    -0x270(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x218(%rbp),%eax
mov    %eax,-0x264(%rbp)
mov    -0x248(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    -0x240(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x264(%rbp),%edi
mov    -0x260(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x218(%rbp),%edi
call   1090 <close@plt>
mov    0x2c05(%rip),%rax
mov    (%rax),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    0x2e36(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe1b(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0xc27,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
lea    0xdfd(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1f4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1230 <main+0x90>
mov    %eax,%ecx
movb   $0x0,0x10(%rsp,%rcx,1)
lea    0xdcf(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
call   1070 <printf@plt>
lea    0xdab(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0xd95(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xd77(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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
@.str = [14 x i8] c"128.10.12.141\00"
@.str.1 = [3 x i8] c"3\0A\00"
@.str.2 = [7 x i8] c"45,46\0A\00"
@.str.3 = [7 x i8] c"45,47\0A\00"
@.str.4 = [3 x i8] c"1\0A\00"
@.str.5 = [26 x i8] c"Received: %s (%d bytes).\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [501 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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* %8
%17 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i32 @htons(i32 3111)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %8
%26 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%27 = call i32 @connect(i32 %25, %struct.sockaddr* %26, i32 4)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %13
%28 = load i32, i32* %8
%29 = load i8*, i8** %10
%30 = load i8*, i8** %10
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @send(i32 %28, i8* %29, i32 %31, i32 0)
br label %33
33: ; preds = %2, %40
%34 = load i32, i32* %8
%35 = getelementptr inbounds [501 x i8], [501 x i8]* %6, i64 0, i64 0
%36 = call i32 @recv(i32 %34, i8* %35, i32 500, i32 0)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
br label %41
40: ; preds = %33
br label %33
41: ; preds = %39
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [501 x i8], [501 x i8]* %6, i64 0, i64 %43
store i8 0, i8* %44
%45 = getelementptr inbounds [501 x i8], [501 x i8]* %6, i64 0, i64 0
%46 = load i32, i32* %7
%47 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %45, i32 %46)
%48 = load i32, i32* %8
%49 = load i8*, i8** %11
%50 = load i8*, i8** %11
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @send(i32 %48, i8* %49, i32 %51, i32 0)
%53 = load i32, i32* %8
%54 = load i8*, i8** %12
%55 = load i8*, i8** %12
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @send(i32 %53, i8* %54, i32 %56, i32 0)
%58 = load i32, i32* %8
%59 = load i8*, i8** %13
%60 = load i8*, i8** %12
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @send(i32 %58, i8* %59, i32 %61, i32 0)
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* @EXIT_SUCCESS
ret i32 %65
}

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
@.str = [14 x i8] c"128.10.12.141\00"
@.str.1 = [3 x i8] c"3\0A\00"
@.str.2 = [7 x i8] c"45,46\0A\00"
@.str.3 = [7 x i8] c"45,47\0A\00"
@.str.4 = [3 x i8] c"1\0A\00"
@.str.5 = [26 x i8] c"Received: %s (%d bytes).\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [501 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @htons(i32 3111)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%18 = call i32 @connect(i32 %9, %struct.sockaddr* %17, i32 4)
%19 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @send(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 0)
br label %21
21: ; preds = %21, %2
%22 = call i32 @recv(i32 %9, i8* %5, i32 500, i32 0)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %21
24: ; preds = %21
%25 = zext i32 %22 to i64
%26 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %5, i32 %22)
%28 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @send(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 0)
%30 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @send(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 0)
%32 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @send(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 0)
%34 = call i32 @close(i32 %9)
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}