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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s [Server IP]\n", argv[0]);
    exit(1);
  }
  int sockFD;
  if ((sockFD = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "socket() error\n");
    exit(1);
  }
  struct sockaddr_in servAddr;
  bzero(&servAddr, sizeof(servAddr));
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(57345);
  if (inet_pton(AF_INET, argv[1], &servAddr.sin_addr) <= 0) {
    fprintf(stderr, "inet_pton() error for %s\n", argv[1]);
    exit(1);
  }
  if (connect(sockFD, (const struct sockaddr *)&servAddr, sizeof(servAddr)) <
      0) {
    fprintf(stderr, "connect() error\n");
    exit(1);
  }
  int len;
  char recvLine[256];
  while ((len = (int)read(sockFD, recvLine, 255)) > 0) {
    recvLine[len] = 0;
    fprintf(stdout, "%s\n", recvLine);
  }
  if (len < 0) {
    fprintf(stderr, "read() error\n");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cb <main+0x4b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1211 <main+0x91>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xe001,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <inet_pton@plt>
cmp    $0x0,%rax
jg     1285 <main+0x105>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    12c1 <main+0x141>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12c6 <main+0x146>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xff,%edx
call   1040 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1315 <main+0x195>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12c6 <main+0x146>
cmpl   $0x0,-0x24(%rbp)
jge    1340 <main+0x1c0>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1281 <main+0x101>
mov    0x2e48(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1296 <main+0x116>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0xe001,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    0x8(%r14),%rsi
mov    %r15,%rdx
call   1060 <inet_pton@plt>
test   %rax,%rax
jle    12a8 <main+0x128>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     12cd <main+0x14d>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xff,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    126a <main+0xea>
mov    0x2d9d(%rip),%r15
lea    0xe0b(%rip),%r14
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1240 <main+0xc0>
test   $0x80000000,%eax
jne    12df <main+0x15f>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd6c(%rip),%rsi
jmp    12bc <main+0x13c>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd71(%rip),%rsi
jmp    12ef <main+0x16f>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xd6b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
jmp    12ef <main+0x16f>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s [Server IP]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() error\0A\00"
@.str.2 = [26 x i8] c"inet_pton() error for %s\0A\00"
@.str.3 = [17 x i8] c"connect() error\0A\00"
@stdout = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [14 x i8] c"read() error\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
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @htons(i32 57345)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @AF_INET
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%39 = call i64 @inet_pton(i32 %34, i8* %37, i32* %38)
%40 = icmp sle i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %28
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %28
%49 = load i32, i32* %6
%50 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%51 = call i64 @connect(i32 %49, %struct.sockaddr* %50, i32 12)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
br label %58
58: ; preds = %64, %57
%59 = load i32, i32* %6
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%61 = call i64 @read(i32 %59, i8* %60, i32 255)
%62 = trunc i64 %61 to i32
store i32 %62, i32* %8
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %58
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %66
store i8 0, i8* %67
%68 = load i32, i32* @stdout
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %69)
br label %58
71: ; preds = %58
%72 = load i32, i32* %8
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %71
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s [Server IP]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() error\0A\00"
@.str.2 = [26 x i8] c"inet_pton() error for %s\0A\00"
@.str.3 = [17 x i8] c"connect() error\0A\00"
@stdout = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [14 x i8] c"read() error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = bitcast %struct.sockaddr_in* %3 to i8*
%22 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 57345)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%31 = call i64 @inet_pton(i32 %27, i8* %29, i32* %30)
%32 = icmp slt i64 %31, 1
br i1 %32, label %33, label %38
33: ; preds = %20
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %28
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %20
%39 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%40 = call i64 @connect(i32 %14, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%48 = call i64 @read(i32 %14, i8* %47, i32 255)
%49 = trunc i64 %48 to i32
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %46, %51
%52 = phi i64 [ %58, %51 ], [ %48, %46 ]
%53 = shl i64 %52, 32
%54 = ashr exact i64 %53, 32
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %54
store i8 0, i8* %55
%56 = load i32, i32* @stdout
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%58 = call i64 @read(i32 %14, i8* %47, i32 255)
%59 = trunc i64 %58 to i32
%60 = icmp sgt i32 %59, 0
br i1 %60, label %51, label %61
61: ; preds = %51, %46
%62 = phi i64 [ %48, %46 ], [ %58, %51 ]
%63 = and i64 %62, 2147483648
%64 = icmp eq i64 %63, 0
br i1 %64, label %69, label %65
65: ; preds = %61
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %61
ret i32 0
}