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

/* Variables and functions */
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket_connect(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  char buffer[1024];
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <hostname> <port>\n", argv[0]);
    exit(1);
  }
  fd = socket_connect(argv[1], atoi(argv[2]));
  write(fd, "GET /\r\n", strlen("GET /\r\n"));
  bzero(buffer, 1024);
  while (read(fd, buffer, 1024 - 1) != 0) {
    fprintf(stderr, "%s", buffer);
    bzero(buffer, 1024);
  }
  shutdown(fd, SHUT_RDWR);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11e9 <main+0x49>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%esi
call   1090 <socket_connect@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x424(%rbp)
lea    0xdf7(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x424(%rbp),%edi
mov    %eax,%edx
lea    0xde3(%rip),%rsi
call   1030 <write@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
je     12a0 <main+0x100>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xda0(%rip),%rsi
call   1080 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
jmp    1250 <main+0xb0>
mov    -0x14(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jle    1276 <main+0xd6>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <socket_connect@plt>
mov    %eax,%ebp
lea    0xe47(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
test   %rax,%rax
je     124f <main+0xaf>
mov    0x2dc3(%rip),%r15
lea    0xe09(%rip),%r14
mov    %rsp,%rbx
nop
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
test   %rax,%rax
jne    1220 <main+0x80>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <shutdown@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd77(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s <hostname> <port>\0A\00"
@.str.1 = [8 x i8] c"GET /\0D\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
%25 = call i32 @socket_connect(i8* %20, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @write(i32 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = call i32 @bzero(i8* %29, i32 1024)
br label %31
31: ; preds = %36, %17
%32 = load i32, i32* %6
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i64 @read(i32 %32, i8* %33, i32 1023)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%41 = call i32 @bzero(i8* %40, i32 1024)
br label %31
42: ; preds = %31
%43 = load i32, i32* %6
%44 = load i32, i32* @SHUT_RDWR
%45 = call i32 @shutdown(i32 %43, i32 %44)
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s <hostname> <port>\0A\00"
@.str.1 = [8 x i8] c"GET /\0D\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = tail call i32 @socket_connect(i8* %13, i32 %16)
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @write(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @bzero(i8* %4, i32 1024)
%21 = call i64 @read(i32 %17, i8* %4, i32 1023)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %11, %23
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%26 = call i32 @bzero(i8* %4, i32 1024)
%27 = call i64 @read(i32 %17, i8* %4, i32 1023)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %23
29: ; preds = %23, %11
%30 = load i32, i32* @SHUT_RDWR
%31 = call i32 @shutdown(i32 %17, i32 %30)
%32 = call i32 @close(i32 %17)
ret i32 0
}