#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;
scalar_t__ EOF;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int sockfd, n;
  char recvline[4096 + 1];
  struct sockaddr_in servaddr;
  if (argc != 2)
    return 1;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    return 1;
  }
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(13);
  if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) < 0) {
    perror("inet_pton");
    return 1;
  }
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    perror("connect");
    return 1;
  }
  while ((n = read(sockfd, recvline, 4096)) > 0) {
    recvline[n] = 0;
    if (fputs(recvline, stdout) == EOF)
      perror("fputs");
  }
  if (n < 0) {
    perror("read");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x197>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ec <main+0x6c>
lea    0xe25(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x197>
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1028(%rbp)
mov    $0xd,%edi
call   1030 <htons@plt>
mov    %eax,-0x102c(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x1030(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x0,%rax
jge    125d <main+0xdd>
lea    0xdbb(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x197>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1293 <main+0x113>
lea    0xd8f(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x197>
jmp    1298 <main+0x118>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    12fa <main+0x17a>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2d00(%rip),%rcx
cmp    (%rcx),%rax
jne    12f5 <main+0x175>
lea    0xd29(%rip),%rdi
call   1080 <perror@plt>
jmp    1298 <main+0x118>
cmpl   $0x0,-0x18(%rbp)
jge    1310 <main+0x190>
lea    0xd14(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1020,%rsp
mov    $0x1,%r14d
cmp    $0x2,%edi
jne    12b3 <main+0x133>
mov    %rsi,%rbx
mov    0x2e40(%rip),%r12
mov    (%r12),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1295 <main+0x115>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    $0xd,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%edi
mov    0x8(%rbx),%rsi
mov    %r15,%rdx
call   1070 <inet_pton@plt>
test   %rax,%rax
js     129e <main+0x11e>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     12a7 <main+0x127>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1285 <main+0x105>
mov    0x2d8d(%rip),%r15
lea    0x10(%rsp),%rbx
mov    0x2d99(%rip),%r12
lea    0xdcb(%rip),%r14
jmp    1263 <main+0xe3>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1285 <main+0x105>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    (%r12),%rax
jne    1250 <main+0xd0>
mov    %r14,%rdi
call   1080 <perror@plt>
jmp    1250 <main+0xd0>
xor    %r14d,%r14d
test   %eax,%eax
jns    12b3 <main+0x133>
lea    0xd8c(%rip),%rdi
jmp    12ae <main+0x12e>
lea    0xd64(%rip),%rdi
jmp    12ae <main+0x12e>
lea    0xd62(%rip),%rdi
jmp    12ae <main+0x12e>
lea    0xd63(%rip),%rdi
call   1080 <perror@plt>
mov    %r14d,%eax
add    $0x1020,%rsp
pop    %rbx
pop    %r12
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
@.str = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"inet_pton\00"
@.str.2 = [8 x i8] c"connect\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.3 = [6 x i8] c"fputs\00"
@.str.4 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4097 x i8]
%9 = alloca %struct.sockaddr_in
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 %13
12: ; preds = %2
store i32 1, i32* %3
br label %66
13: ; preds = %2
%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* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %66
20: ; preds = %13
%21 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 13)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%31 = call i64 @inet_pton(i32 %26, i8* %29, i32* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %66
35: ; preds = %20
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%38 = call i64 @connect(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %66
42: ; preds = %35
br label %43
43: ; preds = %59, %42
%44 = load i32, i32* %6
%45 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 4096)
store i32 %46, i32* %7
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %43
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 %50
store i8 0, i8* %51
%52 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%53 = load i32, i32* @stdout
%54 = call i64 @fputs(i8* %52, i32 %53)
%55 = load i64, i64* @EOF
%56 = icmp eq i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %48
%58 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %48
br label %43
60: ; preds = %43
%61 = load i32, i32* %7
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %65
65: ; preds = %63, %60
store i32 0, i32* %3
br label %66
66: ; preds = %65, %40, %33, %18, %12
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"inet_pton\00"
@.str.2 = [8 x i8] c"connect\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.3 = [6 x i8] c"fputs\00"
@.str.4 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4097 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %56
8: ; preds = %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %56
15: ; preds = %8
%16 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 13)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%25 = call i64 @inet_pton(i32 %21, i8* %23, i32* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %56
29: ; preds = %15
%30 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%31 = call i64 @connect(i32 %11, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = call i32 @read(i32 %11, i8* %5, i32 4096)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %38, label %51
36: ; preds = %29
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %56
38: ; preds = %33, %48
%39 = phi i32 [ %49, %48 ], [ %34, %33 ]
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %41
%42 = load i32, i32* @stdout
%43 = call i64 @fputs(i8* %5, i32 %42)
%44 = load i64, i64* @EOF
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %38
%49 = call i32 @read(i32 %11, i8* %5, i32 4096)
%50 = icmp sgt i32 %49, 0
br i1 %50, label %38, label %51
51: ; preds = %48, %33
%52 = phi i32 [ %34, %33 ], [ %49, %48 ]
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %51, %54, %2, %36, %27, %13
%57 = phi i32 [ 1, %13 ], [ 1, %27 ], [ 1, %36 ], [ 1, %2 ], [ 0, %54 ], [ 0, %51 ]
ret i32 %57
}