#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 */
typedef int /*<<< orphan*/ u_char;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
scalar_t__ recv(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ send(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/ *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
size_t strlen(int /*<<< orphan*/ *);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *);
int http_fetch(struct sockaddr_in *sin, char *path, int quiet) {
  u_char buffer[(48 * 1024)];
  ssize_t len;
  size_t sofar;
  int sock;
  sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    if (!quiet)
      warn("socket(PF_INET, SOCK_STREAM)");
    return (-1);
  }
  if (connect(sock, (struct sockaddr *)sin, sizeof(*sin)) < 0) {
    if (!quiet)
      warn("connect");
    close(sock);
    return (-1);
  }
  snprintf(buffer, (48 * 1024), "GET %s HTTP/1.0\n\n", path);
  sofar = 0;
  while (sofar < strlen(buffer)) {
    len = send(sock, buffer, strlen(buffer), 0);
    if (len < 0) {
      if (!quiet)
        warn("send");
      close(sock);
      return (-1);
    }
    if (len == 0) {
      if (!quiet)
        warnx("send: len == 0");
    }
    sofar += len;
  }
  while (1) {
    len = recv(sock, buffer, (48 * 1024), 0);
    if (len < 0) {
      if (!quiet)
        warn("recv");
      close(sock);
      return (-1);
    }
    if (len == 0)
      break;
  }
  close(sock);
  return (0);
}


x86 assembly (clang, -O0):
<http_fetch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30050,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x30034(%rbp)
cmpl   $0x0,-0x30034(%rbp)
jge    11f4 <http_fetch+0x64>
cmpl   $0x0,-0x1c(%rbp)
jne    11e8 <http_fetch+0x58>
lea    0xe1d(%rip),%rdi
call   1040 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <http_fetch+0x24f>
mov    -0x30034(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    123f <http_fetch+0xaf>
cmpl   $0x0,-0x1c(%rbp)
jne    1228 <http_fetch+0x98>
lea    0xdfa(%rip),%rdi
call   1040 <warn@plt>
mov    -0x30034(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <http_fetch+0x24f>
lea    -0x30020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xc000,%esi
lea    0xdcf(%rip),%rdx
call   1080 <snprintf@plt>
movq   $0x0,-0x30030(%rbp)
mov    -0x30030(%rbp),%rax
mov    %rax,-0x30040(%rbp)
lea    -0x30020(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30040(%rbp),%rax
cmp    %rcx,%rax
jae    1355 <http_fetch+0x1c5>
mov    -0x30034(%rbp),%eax
mov    %eax,-0x3004c(%rbp)
lea    -0x30020(%rbp),%rax
mov    %rax,-0x30048(%rbp)
lea    -0x30020(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3004c(%rbp),%edi
mov    -0x30048(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x30028(%rbp)
cmpq   $0x0,-0x30028(%rbp)
jge    1312 <http_fetch+0x182>
cmpl   $0x0,-0x1c(%rbp)
jne    12fb <http_fetch+0x16b>
lea    0xd41(%rip),%rdi
call   1040 <warn@plt>
mov    -0x30034(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <http_fetch+0x24f>
cmpq   $0x0,-0x30028(%rbp)
jne    133b <http_fetch+0x1ab>
cmpl   $0x0,-0x1c(%rbp)
jne    1336 <http_fetch+0x1a6>
lea    0xd0b(%rip),%rdi
call   1070 <warnx@plt>
jmp    133b <http_fetch+0x1ab>
mov    -0x30028(%rbp),%rax
add    -0x30030(%rbp),%rax
mov    %rax,-0x30030(%rbp)
jmp    1266 <http_fetch+0xd6>
jmp    135a <http_fetch+0x1ca>
mov    -0x30034(%rbp),%edi
lea    -0x30020(%rbp),%rsi
mov    $0xc000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x30028(%rbp)
cmpq   $0x0,-0x30028(%rbp)
jge    13b5 <http_fetch+0x225>
cmpl   $0x0,-0x1c(%rbp)
jne    139e <http_fetch+0x20e>
lea    0xcb2(%rip),%rdi
call   1040 <warn@plt>
mov    -0x30034(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <http_fetch+0x24f>
cmpq   $0x0,-0x30028(%rbp)
jne    13c8 <http_fetch+0x238>
jmp    13cd <http_fetch+0x23d>
jmp    135a <http_fetch+0x1ca>
mov    -0x30034(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_fetch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30008,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     125c <http_fetch+0xcc>
mov    %eax,%r13d
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     12a5 <http_fetch+0x115>
lea    0xe38(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xc000,%esi
mov    %r15,%rcx
call   1080 <snprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     1274 <http_fetch+0xe4>
xor    %ebx,%ebx
mov    %rsp,%r12
lea    0xe23(%rip),%r15
jmp    1230 <http_fetch+0xa0>
nopl   0x0(%rax,%rax,1)
add    %rbp,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbx
jae    1274 <http_fetch+0xe4>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
js     12c1 <http_fetch+0x131>
mov    %rax,%rbp
test   %r14d,%r14d
jne    1220 <http_fetch+0x90>
test   %rbp,%rbp
jne    1220 <http_fetch+0x90>
mov    %r15,%rdi
call   1070 <warnx@plt>
jmp    1220 <http_fetch+0x90>
mov    $0xffffffff,%ebx
test   %r14d,%r14d
jne    12df <http_fetch+0x14f>
lea    0xd93(%rip),%rdi
call   1040 <warn@plt>
jmp    12df <http_fetch+0x14f>
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xc000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     12b3 <http_fetch+0x123>
jne    1280 <http_fetch+0xf0>
mov    %r13d,%edi
call   1090 <close@plt>
xor    %ebx,%ebx
jmp    12df <http_fetch+0x14f>
test   %r14d,%r14d
jne    12d2 <http_fetch+0x142>
lea    0xd6c(%rip),%rdi
jmp    12cd <http_fetch+0x13d>
test   %r14d,%r14d
jne    12d2 <http_fetch+0x142>
lea    0xd8c(%rip),%rdi
jmp    12cd <http_fetch+0x13d>
test   %r14d,%r14d
jne    12d2 <http_fetch+0x142>
lea    0xd6a(%rip),%rdi
call   1040 <warn@plt>
mov    %r13d,%edi
call   1090 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x30008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [29 x i8] c"socket(PF_INET, SOCK_STREAM)\00"
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [18 x i8] c"GET %s HTTP/1.0\0A\0A\00"
@.str.3 = [5 x i8] c"send\00"
@.str.4 = [15 x i8] c"send: len == 0\00"
@.str.5 = [5 x i8] c"recv\00"
define i32 @http_fetch(%struct.sockaddr_in* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [49152 x i32]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
store i32 -1, i32* %4
br label %98
23: ; preds = %3
%24 = load i32, i32* %11
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%26 = bitcast %struct.sockaddr_in* %25 to %struct.sockaddr*
%27 = call i64 @connect(i32 %24, %struct.sockaddr* %26, i32 4)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* %11
%36 = call i32 @close(i32 %35)
store i32 -1, i32* %4
br label %98
37: ; preds = %23
%38 = getelementptr inbounds [49152 x i32], [49152 x i32]* %8, i64 0, i64 0
%39 = load i8*, i8** %6
%40 = call i32 @snprintf(i32* %38, i32 49152, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %39)
store i64 0, i64* %10
br label %41
41: ; preds = %71, %37
%42 = load i64, i64* %10
%43 = getelementptr inbounds [49152 x i32], [49152 x i32]* %8, i64 0, i64 0
%44 = call i64 @strlen(i32* %43)
%45 = icmp ult i64 %42, %44
br i1 %45, label %46, label %75
46: ; preds = %41
%47 = load i32, i32* %11
%48 = getelementptr inbounds [49152 x i32], [49152 x i32]* %8, i64 0, i64 0
%49 = getelementptr inbounds [49152 x i32], [49152 x i32]* %8, i64 0, i64 0
%50 = call i64 @strlen(i32* %49)
%51 = call i64 @send(i32 %47, i32* %48, i64 %50, i32 0)
store i64 %51, i64* %9
%52 = load i64, i64* %9
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %46
%55 = load i32, i32* %7
%56 = icmp ne i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %54
%60 = load i32, i32* %11
%61 = call i32 @close(i32 %60)
store i32 -1, i32* %4
br label %98
62: ; preds = %46
%63 = load i64, i64* %9
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* %7
%67 = icmp ne i32 %66, 0
br i1 %67, label %70, label %68
68: ; preds = %65
%69 = call i32 @warnx(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
br label %71
71: ; preds = %70, %62
%72 = load i64, i64* %9
%73 = load i64, i64* %10
%74 = add i64 %73, %72
store i64 %74, i64* %10
br label %41
75: ; preds = %41
br label %76
76: ; preds = %75, %94
%77 = load i32, i32* %11
%78 = getelementptr inbounds [49152 x i32], [49152 x i32]* %8, i64 0, i64 0
%79 = call i64 @recv(i32 %77, i32* %78, i32 49152, i32 0)
store i64 %79, i64* %9
%80 = load i64, i64* %9
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %90
82: ; preds = %76
%83 = load i32, i32* %7
%84 = icmp ne i32 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %82
%86 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = load i32, i32* %11
%89 = call i32 @close(i32 %88)
store i32 -1, i32* %4
br label %98
90: ; preds = %76
%91 = load i64, i64* %9
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %90
br label %95
94: ; preds = %90
br label %76
95: ; preds = %93
%96 = load i32, i32* %11
%97 = call i32 @close(i32 %96)
store i32 0, i32* %4
br label %98
98: ; preds = %95, %87, %59, %34, %22
%99 = load i32, i32* %4
ret i32 %99
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [29 x i8] c"socket(PF_INET, SOCK_STREAM)\00"
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [18 x i8] c"GET %s HTTP/1.0\0A\0A\00"
@.str.3 = [5 x i8] c"send\00"
@.str.4 = [15 x i8] c"send: len == 0\00"
@.str.5 = [5 x i8] c"recv\00"
define i32 @http_fetch(%struct.sockaddr_in* %0, i8* %1, i32 %2) {
%4 = alloca [49152 x i32]
%5 = bitcast [49152 x i32]* %4 to i8*
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = icmp eq i32 %2, 0
br i1 %11, label %12, label %65
12: ; preds = %10
%13 = tail call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %65
14: ; preds = %3
%15 = bitcast %struct.sockaddr_in* %0 to %struct.sockaddr*
%16 = tail call i64 @connect(i32 %8, %struct.sockaddr* %15, i32 4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = icmp eq i32 %2, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = tail call i32 @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = tail call i32 @close(i32 %8)
br label %65
24: ; preds = %14
%25 = getelementptr inbounds [49152 x i32], [49152 x i32]* %4, i64 0, i64 0
%26 = call i32 @snprintf(i32* %25, i32 49152, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%27 = call i64 @strlen(i32* %25)
%28 = icmp eq i64 %27, 0
br i1 %28, label %51, label %29
29: ; preds = %24
%30 = icmp ne i32 %2, 0
br label %31
31: ; preds = %29, %47
%32 = phi i64 [ %27, %29 ], [ %49, %47 ]
%33 = phi i64 [ 0, %29 ], [ %48, %47 ]
%34 = call i64 @send(i32 %8, i32* %25, i64 %32, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = icmp eq i32 %2, 0
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
%41 = call i32 @close(i32 %8)
br label %65
42: ; preds = %31
%43 = icmp ne i64 %34, 0
%44 = or i1 %30, %43
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = call i32 @warnx(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = add i64 %34, %33
%49 = call i64 @strlen(i32* %25)
%50 = icmp ult i64 %48, %49
br i1 %50, label %31, label %51
51: ; preds = %47, %24
br label %52
52: ; preds = %51, %61
%53 = call i64 @recv(i32 %8, i32* %25, i32 49152, i32 0)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %52
%56 = icmp eq i32 %2, 0
br i1 %56, label %57, label %59
57: ; preds = %55
%58 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %59
59: ; preds = %57, %55
%60 = call i32 @close(i32 %8)
br label %65
61: ; preds = %52
%62 = icmp eq i64 %53, 0
br i1 %62, label %63, label %52
63: ; preds = %61
%64 = call i32 @close(i32 %8)
br label %65
65: ; preds = %10, %12, %63, %59, %40, %22
%66 = phi i32 [ -1, %22 ], [ -1, %40 ], [ -1, %59 ], [ 0, %63 ], [ -1, %12 ], [ -1, %10 ]
ret i32 %66
}