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

/* Variables and functions */
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ http_request_headers(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argv[1] == NULL) {
    printf("Usage: ./bug1 [s|l]\n");
    return 1;
  }
  FILE *fp;
  if (strcmp(argv[1], "s") == 0)
    fp = fopen("small_input.txt", "r");
  else if (strcmp(argv[1], "l") == 0)
    fp = fopen("large_input.txt", "r");
  else {
    printf("%s is not a valid argument\n", argv[1]);
    return 2;
  }
  int fd = fileno(fp);
  http_request_headers(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    118f <main+0x3f>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c9 <main+0x79>
lea    0xe63(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    122a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1203 <main+0xb3>
lea    0xe3d(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1225 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    123e <main+0xee>
jmp    122a <main+0xda>
mov    -0x18(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <http_request_headers@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     11ac <main+0x4c>
mov    %rsi,%rbx
lea    0xe8c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11bf <main+0x5f>
mov    0x8(%rbx),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c8 <main+0x68>
mov    0x8(%rbx),%rsi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%eax
pop    %rbx
ret
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe3c(%rip),%rdi
jmp    11cf <main+0x6f>
lea    0xe47(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1040 <http_request_headers@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: ./bug1 [s|l]\0A\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [16 x i8] c"small_input.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"l\00"
@.str.5 = [16 x i8] c"large_input.txt\00"
@.str.6 = [28 x i8] c"%s is not a valid argument\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %41
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %6
br label %36
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %6
br label %35
30: ; preds = %22
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %33)
store i32 2, i32* %3
br label %41
35: ; preds = %28
br label %36
36: ; preds = %35, %20
%37 = load i32*, i32** %6
%38 = call i32 @fileno(i32* %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = call i32 @http_request_headers(i32 %39)
br label %41
41: ; preds = %36, %30, %12
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [16 x i8] c"small_input.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"l\00"
@.str.5 = [16 x i8] c"large_input.txt\00"
@.str.6 = [28 x i8] c"%s is not a valid argument\0A\00"
@str = [20 x i8] c"Usage: ./bug1 [s|l]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %23
8: ; preds = %2
%9 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %16)
br label %23
18: ; preds = %11, %8
%19 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), %11 ]
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @fileno(i32* %20)
%22 = tail call i32 @http_request_headers(i32 %21)
br label %23
23: ; preds = %15, %18, %6
%24 = phi i32 [ 1, %6 ], [ 0, %18 ], [ 2, %15 ]
ret i32 %24
}