#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 recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int retrievePage(int sock, int year, int month, int day, char *airport,
                 char *input, int max) {
  int offset = 0, status;
  char request[128];
  if (!strcmp(airport, "")) {
    return 0;
  }
  sprintf(request,
          "GET /history/airport/%s/%04d/%02d/%02d/MonthlyHistory.html?format=1 "
          "HTTP/1.0\n\n",
          airport, year, month, day);
  status = send(sock, request, strlen(request), 0);
  if (status < 0) {
    return -1;
  }
  status = 1;
  while (status > 0) {
    status = recv(sock, input + offset, max - offset, 0);
    offset += status;
  }
  return offset;
}


x86 assembly (clang, -O0):
<retrievePage>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeca(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    119e <retrievePage+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1255 <retrievePage+0x105>
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    0xe45(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1212 <retrievePage+0xc2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1255 <retrievePage+0x105>
movl   $0x1,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    124f <retrievePage+0xff>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rax
add    %rax,%rsi
mov    0x10(%rbp),%edx
sub    -0x2c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1219 <retrievePage+0xc9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retrievePage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
cmpb   $0x0,(%r8)
je     11bd <retrievePage+0x7d>
mov    %r9,%r14
mov    %ecx,%r9d
mov    %edx,%eax
mov    %esi,%ecx
mov    %edi,%ebp
lea    0xe9a(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r8,%rdx
mov    %eax,%r8d
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %eax,%eax
js     11c1 <retrievePage+0x81>
mov    0xb0(%rsp),%r15d
nopl   0x0(%rax,%rax,1)
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rsi
mov    %r15d,%edx
sub    %ebx,%edx
mov    %ebp,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
add    %eax,%ebx
test   %eax,%eax
jg     11a0 <retrievePage+0x60>
jmp    11c6 <retrievePage+0x86>
xor    %ebx,%ebx
jmp    11c6 <retrievePage+0x86>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [79 x i8] c"GET /history/airport/%s/%04d/%02d/%02d/MonthlyHistory.html?format=1 HTTP/1.0\0A\0A\00"
define i32 @retrievePage(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [128 x i8]
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i32 %6, i32* %15
store i32 0, i32* %16
%19 = load i8*, i8** %13
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %7
store i32 0, i32* %8
br label %57
23: ; preds = %7
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%25 = load i8*, i8** %13
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = load i32, i32* %12
%29 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %9
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @send(i32 %30, i8* %31, i32 %33, i32 0)
store i32 %34, i32* %17
%35 = load i32, i32* %17
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %23
store i32 -1, i32* %8
br label %57
38: ; preds = %23
store i32 1, i32* %17
br label %39
39: ; preds = %42, %38
%40 = load i32, i32* %17
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %39
%43 = load i32, i32* %9
%44 = load i8*, i8** %14
%45 = load i32, i32* %16
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i32, i32* %15
%49 = load i32, i32* %16
%50 = sub nsw i32 %48, %49
%51 = call i32 @recv(i32 %43, i8* %47, i32 %50, i32 0)
store i32 %51, i32* %17
%52 = load i32, i32* %17
%53 = load i32, i32* %16
%54 = add nsw i32 %53, %52
store i32 %54, i32* %16
br label %39
55: ; preds = %39
%56 = load i32, i32* %16
store i32 %56, i32* %8
br label %57
57: ; preds = %55, %37, %22
%58 = load i32, i32* %8
ret i32 %58
}

LLVM IR (-O2):
@.str.1 = [79 x i8] c"GET /history/airport/%s/%04d/%02d/%02d/MonthlyHistory.html?format=1 HTTP/1.0\0A\0A\00"
define i32 @retrievePage(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca [128 x i8]
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %7
%13 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %1, i32 %2, i32 %3)
%14 = call i32 @strlen(i8* %9)
%15 = call i32 @send(i32 %0, i8* %9, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %12, %17
%18 = phi i32 [ %23, %17 ], [ 0, %12 ]
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %5, i64 %19
%21 = sub nsw i32 %6, %18
%22 = call i32 @recv(i32 %0, i8* %20, i32 %21, i32 0)
%23 = add nsw i32 %22, %18
%24 = icmp sgt i32 %22, 0
br i1 %24, label %17, label %25
25: ; preds = %17, %12, %7
%26 = phi i32 [ 0, %7 ], [ -1, %12 ], [ %23, %17 ]
ret i32 %26
}