#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*/ close(int);
int /*<<< orphan*/ die(char *, int, ...);
int /*<<< orphan*/ free(char *);
int net_connect_tcp(char *, char *, int /*<<< orphan*/);
char *net_receive(int);
int prepare(char **, char *, int, char *, char *);
int send(int, char *, int, int /*<<< orphan*/);
char *strstr(char *, char *);
char *http(char *host, char *loc) {
  char *packet;
  int s = net_connect_tcp(host, "http", 0);
  if (s < 0)
    die("Connect", 0);
  char *cmd = "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Windows "
              "NT 6.1; WOW64; rv:12.0) Gecko/20100101 "
              "Firefox/12.0\r\nConnection: close\r\n\r\n";
  int len = prepare(&packet, cmd, 2, loc, host);
  int r = send(s, packet, len, 0);
  free(packet);
  if (r < 0)
    die("Send", 1, s);
  do {
    if ((packet = net_receive(s)) == NULL)
      die("Receive", 1, s);
    while (strstr(packet, "HTTP/1.1 100 Continue\r\n") != NULL)
      packet = strstr(packet, "\r\n\r\n") + 4;
    packet = strstr(packet, "\r\n\r\n");
  } while (packet == NULL);
  packet += 4;
  close(s);
  return packet;
}


x86 assembly (clang, -O0):
<http>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
xor    %edx,%edx
call   1070 <net_connect_tcp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bf <http+0x3f>
lea    0xe4f(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1090 <die@plt>
lea    0xe47(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    -0x18(%rbp),%rdi
mov    $0x2,%edx
call   1060 <prepare@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x30(%rbp)
jge    1224 <http+0xa4>
mov    -0x1c(%rbp),%edx
lea    0xe7c(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1090 <die@plt>
jmp    1229 <http+0xa9>
mov    -0x1c(%rbp),%edi
call   1080 <net_receive@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1255 <http+0xd5>
mov    -0x1c(%rbp),%edx
lea    0xe50(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1090 <die@plt>
jmp    125a <http+0xda>
mov    -0x18(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1291 <http+0x111>
mov    -0x18(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   10a0 <strstr@plt>
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    125a <http+0xda>
mov    -0x18(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1229 <http+0xa9>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe67(%rip),%rsi
xor    %edx,%edx
call   1070 <net_connect_tcp@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    11b7 <http+0x37>
lea    0xe57(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1090 <die@plt>
lea    0xe4f(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    $0x2,%edx
mov    %rbp,%rcx
mov    %rbx,%r8
call   1060 <prepare@plt>
mov    0x8(%rsp),%rsi
mov    %r15d,%edi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
test   %ebx,%ebx
jns    120a <http+0x8a>
lea    0xe99(%rip),%rdi
mov    $0x1,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <die@plt>
lea    0xe88(%rip),%r14
lea    0xe89(%rip),%r12
lea    0xe70(%rip),%rbp
nop
mov    %r15d,%edi
call   1080 <net_receive@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    1261 <http+0xe1>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <die@plt>
mov    0x8(%rsp),%rbx
jmp    1261 <http+0xe1>
xchg   %ax,%ax
call   10a0 <strstr@plt>
mov    %rax,%rbx
add    $0x4,%rbx
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strstr@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
test   %rax,%rax
jne    1250 <http+0xd0>
call   10a0 <strstr@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1220 <http+0xa0>
add    $0x4,%rax
mov    %rax,0x8(%rsp)
mov    %r15d,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"http\00"
@.str.1 = [8 x i8] c"Connect\00"
@.str.2 = [135 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.3 = [5 x i8] c"Send\00"
@.str.4 = [8 x i8] c"Receive\00"
@.str.5 = [24 x i8] c"HTTP/1.1 100 Continue\0D\0A\00"
@.str.6 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @http(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32 @net_connect_tcp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, i32, ...) @die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %16
16: ; preds = %14, %2
store i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i8** %7
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = call i32 @prepare(i8** %5, i8* %17, i32 2, i8* %18, i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %6
%22 = load i8*, i8** %5
%23 = load i32, i32* %8
%24 = call i32 @send(i32 %21, i8* %22, i32 %23, i32 0)
store i32 %24, i32* %9
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %16
%30 = load i32, i32* %6
%31 = call i32 (i8*, i32, ...) @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %30)
br label %32
32: ; preds = %29, %16
br label %33
33: ; preds = %52, %32
%34 = load i32, i32* %6
%35 = call i8* @net_receive(i32 %34)
store i8* %35, i8** %5
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* %6
%39 = call i32 (i8*, i32, ...) @die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %38)
br label %40
40: ; preds = %37, %33
br label %41
41: ; preds = %45, %40
%42 = load i8*, i8** %5
%43 = call i8* @strstr(i8* %42, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i8*, i8** %5
%47 = call i8* @strstr(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%48 = getelementptr inbounds i8, i8* %47, i64 4
store i8* %48, i8** %5
br label %41
49: ; preds = %41
%50 = load i8*, i8** %5
%51 = call i8* @strstr(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %51, i8** %5
br label %52
52: ; preds = %49
%53 = load i8*, i8** %5
%54 = icmp eq i8* %53, null
br i1 %54, label %33, label %55
55: ; preds = %52
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 4
store i8* %57, i8** %5
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
%60 = load i8*, i8** %5
ret i8* %60
}

LLVM IR (-O2):
@.str = [5 x i8] c"http\00"
@.str.1 = [8 x i8] c"Connect\00"
@.str.2 = [135 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.3 = [5 x i8] c"Send\00"
@.str.4 = [8 x i8] c"Receive\00"
@.str.5 = [24 x i8] c"HTTP/1.1 100 Continue\0D\0A\00"
@.str.6 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @http(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @net_connect_tcp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, i32, ...) @die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %9
9: ; preds = %7, %2
%10 = call i32 @prepare(i8** %3, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 2, i8* %1, i8* %0)
%11 = load i8*, i8** %3
%12 = call i32 @send(i32 %5, i8* %11, i32 %10, i32 0)
%13 = load i8*, i8** %3
%14 = call i32 @free(i8* %13)
%15 = icmp slt i32 %12, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 (i8*, i32, ...) @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %5)
br label %18
18: ; preds = %16, %9
br label %19
19: ; preds = %18, %35
%20 = call i8* @net_receive(i32 %5)
store i8* %20, i8** %3
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 (i8*, i32, ...) @die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %5)
%24 = load i8*, i8** %3
br label %25
25: ; preds = %22, %19
%26 = phi i8* [ %24, %22 ], [ %20, %19 ]
%27 = call i8* @strstr(i8* dereferenceable(1) %26, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %35, label %29
29: ; preds = %25, %29
%30 = phi i8* [ %32, %29 ], [ %26, %25 ]
%31 = call i8* @strstr(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%32 = getelementptr inbounds i8, i8* %31, i64 4
store i8* %32, i8** %3
%33 = call i8* @strstr(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %29
35: ; preds = %29, %25
%36 = phi i8* [ %26, %25 ], [ %32, %29 ]
%37 = call i8* @strstr(i8* dereferenceable(1) %36, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %37, i8** %3
%38 = icmp eq i8* %37, null
br i1 %38, label %19, label %39
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %37, i64 4
store i8* %40, i8** %3
%41 = call i32 @close(i32 %5)
%42 = load i8*, i8** %3
ret i8* %42
}