#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ error_handler(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ header(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *);
void http_get(FILE *client_write, char *path) {
  char buf[1024];
  FILE *send_file;
  send_file = fopen(path, "r");
  if (send_file == NULL) {
    error_handler(client_write);
    return;
  }
  header(client_write, path);
  printf("send begin");
  fgets(buf, sizeof(buf), send_file);
  while (!feof(send_file)) {
    fputs(buf, client_write);
    fgets(buf, sizeof(buf), send_file);
  }
  printf("send end\n");
  fflush(client_write);
  fclose(client_write);
  fclose(send_file);
}


x86 assembly (clang, -O0):
<http_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11d6 <http_get+0x46>
mov    -0x8(%rbp),%rdi
call   1050 <error_handler@plt>
jmp    127f <http_get+0xef>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <header@plt>
lea    0xe18(%rip),%rdi
call   1060 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
mov    -0x418(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1228 <http_get+0x98>
jmp    1255 <http_get+0xc5>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <fputs@plt>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
jmp    1207 <http_get+0x77>
lea    0xdb1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe47(%rip),%rsi
mov    %r15,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1268 <http_get+0xc8>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <header@plt>
lea    0xe23(%rip),%rdi
call   1070 <printf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1237 <http_get+0x97>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <fputs@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1210 <http_get+0x70>
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10b0 <fflush@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <error_handler@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"send begin\00"
@.str.2 = [10 x i8] c"send end\0A\00"
define void @http_get(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32*, i32** %3
%13 = call i32 @error_handler(i32* %12)
br label %42
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = load i8*, i8** %4
%17 = call i32 @header(i32* %15, i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %6
%21 = call i32 @fgets(i8* %19, i32 1024, i32* %20)
br label %22
22: ; preds = %27, %14
%23 = load i32*, i32** %6
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = load i32*, i32** %3
%30 = call i32 @fputs(i8* %28, i32* %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i32 @fgets(i8* %31, i32 1024, i32* %32)
br label %22
34: ; preds = %22
%35 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32*, i32** %3
%37 = call i32 @fflush(i32* %36)
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %34, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"send begin\00"
@str = [9 x i8] c"send end\00"
define void @http_get(i32* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @error_handler(i32* %0)
br label %25
9: ; preds = %2
%10 = tail call i32 @header(i32* %0, i8* %1)
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @fgets(i8* %4, i32 1024, i32* %5)
%13 = call i32 @feof(i32* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %9, %15
%16 = call i32 @fputs(i8* %4, i32* %0)
%17 = call i32 @fgets(i8* %4, i32 1024, i32* %5)
%18 = call i32 @feof(i32* %5)
%19 = icmp eq i32 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %9
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%22 = call i32 @fflush(i32* %0)
%23 = call i32 @fclose(i32* %0)
%24 = call i32 @fclose(i32* %5)
br label %25
25: ; preds = %20, %7
ret void
}