#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;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(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[65535 + 1];
  struct sockaddr_in servaddr;
  if (argc != 2) {
    printf("usage: a.out <IPaddress>");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    perror("socket error");
  bzero(&servaddr, 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 error");
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
    perror("connect error");
  while ((n = read(sockfd, recvline, 65535)) > 0) {
    recvline[n] = 0;
    if (fputs(recvline, stdout) == EOF)
      perror("fputs error");
  }
  if (n < 0)
    printf("read error\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d9 <main+0x39>
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    120a <main+0x6a>
lea    0xe14(%rip),%rdi
call   1080 <perror@plt>
lea    -0x10030(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10028(%rbp)
mov    $0xd,%edi
call   1030 <htons@plt>
mov    %eax,-0x1002c(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x10030(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x0,%rax
jg     126d <main+0xcd>
lea    0xdbe(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
lea    -0x10030(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    1297 <main+0xf7>
lea    0xda4(%rip),%rdi
call   1080 <perror@plt>
jmp    129c <main+0xfc>
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    $0xffff,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    12fe <main+0x15e>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x10020(%rbp,%rax,1)
lea    -0x10020(%rbp),%rdi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2cfc(%rip),%rcx
cmp    (%rcx),%rax
jne    12f9 <main+0x159>
lea    0xd50(%rip),%rdi
call   1080 <perror@plt>
jmp    129c <main+0xfc>
cmpl   $0x0,-0x18(%rbp)
jge    1314 <main+0x174>
lea    0xd41(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10010,%rsp
cmp    $0x2,%edi
jne    12c7 <main+0x117>
mov    %rsi,%r14
mov    0x2e16(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    11f8 <main+0x48>
lea    0xe26(%rip),%rdi
call   1090 <perror@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x0(%rbp),%edi
mov    0x8(%r14),%rsi
mov    %rbx,%rdx
call   1080 <inet_pton@plt>
test   %rax,%rax
jg     123d <main+0x8d>
lea    0xdee(%rip),%rdi
call   1090 <perror@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
jns    125e <main+0xae>
lea    0xddd(%rip),%rdi
call   1090 <perror@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xffff,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12dd <main+0x12d>
mov    0x2d4d(%rip),%r12
lea    0x10(%rsp),%rbx
mov    0x2d59(%rip),%rbp
lea    0xdb6(%rip),%r14
jmp    12a4 <main+0xf4>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xffff,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12dd <main+0x12d>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <fputs@plt>
cmp    0x0(%rbp),%rax
jne    1290 <main+0xe0>
mov    %r14,%rdi
call   1090 <perror@plt>
jmp    1290 <main+0xe0>
lea    0xd32(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
test   %eax,%eax
jns    12ed <main+0x13d>
lea    0xd68(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"usage: a.out <IPaddress>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [16 x i8] c"inet_pton error\00"
@.str.3 = [14 x i8] c"connect error\00"
@stdout = global i32 0
@EOF = global i64 0
@.str.4 = [12 x i8] c"fputs error\00"
@.str.5 = [12 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 i32
%8 = alloca [65536 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 %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 13)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%33 = call i64 @inet_pton(i32 %28, i8* %31, i32* %32)
%34 = icmp sle i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %22
%36 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %22
%38 = load i32, i32* %6
%39 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%40 = call i64 @connect(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
br label %45
45: ; preds = %61, %44
%46 = load i32, i32* %6
%47 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%48 = call i32 @read(i32 %46, i8* %47, i32 65535)
store i32 %48, i32* %7
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %45
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 %52
store i8 0, i8* %53
%54 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%55 = load i32, i32* @stdout
%56 = call i64 @fputs(i8* %54, i32 %55)
%57 = load i64, i64* @EOF
%58 = icmp eq i64 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %50
%60 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %50
br label %45
62: ; preds = %45
%63 = load i32, i32* %7
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = call i32 @exit(i32 0)
unreachable
}

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