#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 /*<<< orphan*/ GetHtmlHeader(char *, char *);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(int);
void DowningFile(char *filename, char *fname) {
  FILE *fp;
  char *buff;
  long size;
  register long i;
  char htmlheader[100];
  if ((fp = fopen(filename, "rb")) == NULL)
    return;
  fseek(fp, 0L, SEEK_END);
  size = ftell(fp);
  printf("Content-Length: %ld\r\n", size);
  printf(
      "Content-disposition: form-data; name=\"filename\"; filename=\"%s\";\r\n",
      fname);
  GetHtmlHeader(filename, htmlheader);
  printf("Content-type: %s\r\n\r\n", htmlheader);
  if ((buff = (char *)malloc(size)) == NULL) {
    fclose(fp);
    return;
  }
  fseek(fp, 0L, SEEK_SET);
  fread(buff, size, 1, fp);
  fclose(fp);
  for (i = 0; i < size; i++)
    putchar((int)buff[i]);
  free(buff);
}


x86 assembly (clang, -O0):
<DowningFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d6 <DowningFile+0x36>
jmp    12dd <DowningFile+0x13d>
mov    -0x18(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <GetHtmlHeader@plt>
lea    -0xa0(%rbp),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1267 <DowningFile+0xc7>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
jmp    12dd <DowningFile+0x13d>
mov    -0x18(%rbp),%rdi
mov    0x2d66(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <fseek@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    12d4 <DowningFile+0x134>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <putchar@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12a4 <DowningFile+0x104>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DowningFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe48(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1295 <DowningFile+0xf5>
mov    %rax,%r14
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
lea    0xe15(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rsp,%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <GetHtmlHeader@plt>
lea    0xe3d(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     128d <DowningFile+0xed>
mov    %rax,%r12
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
test   %r15,%r15
jle    1283 <DowningFile+0xe3>
xor    %ebx,%ebx
nopl   (%rax)
movsbl (%r12,%rbx,1),%edi
call   1040 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1270 <DowningFile+0xd0>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1295 <DowningFile+0xf5>
mov    %r14,%rdi
call   1070 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [22 x i8] c"Content-Length: %ld\0D\0A\00"
@.str.2 = [66 x i8] c"Content-disposition: form-data; name=\22filename\22; filename=\22%s\22;\0D\0A\00"
@.str.3 = [21 x i8] c"Content-type: %s\0D\0A\0D\0A\00"
@SEEK_SET = global i32 0
define void @DowningFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [100 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
br label %63
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
%18 = load i32*, i32** %5
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %20)
%22 = load i8*, i8** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %3
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%26 = call i32 @GetHtmlHeader(i8* %24, i8* %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i64, i64* %7
%30 = call i64 @malloc(i64 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %14
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
br label %63
36: ; preds = %14
%37 = load i32*, i32** %5
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %37, i64 0, i32 %38)
%40 = load i8*, i8** %6
%41 = load i64, i64* %7
%42 = load i32*, i32** %5
%43 = call i32 @fread(i8* %40, i64 %41, i32 1, i32* %42)
%44 = load i32*, i32** %5
%45 = call i32 @fclose(i32* %44)
store i64 0, i64* %8
br label %46
46: ; preds = %57, %36
%47 = load i64, i64* %8
%48 = load i64, i64* %7
%49 = icmp slt i64 %47, %48
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i8*, i8** %6
%52 = load i64, i64* %8
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = call i32 @putchar(i32 %55)
br label %57
57: ; preds = %50
%58 = load i64, i64* %8
%59 = add nsw i64 %58, 1
store i64 %59, i64* %8
br label %46
60: ; preds = %46
%61 = load i8*, i8** %6
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %60, %33, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [22 x i8] c"Content-Length: %ld\0D\0A\00"
@.str.2 = [66 x i8] c"Content-disposition: form-data; name=\22filename\22; filename=\22%s\22;\0D\0A\00"
@.str.3 = [21 x i8] c"Content-type: %s\0D\0A\0D\0A\00"
@SEEK_SET = global i32 0
define void @DowningFile(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %36, label %7
7: ; preds = %2
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %5, i64 0, i32 %8)
%10 = tail call i64 @ftell(i32* %5)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%13 = call i32 @GetHtmlHeader(i8* %0, i8* %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%15 = call i64 @malloc(i64 %10)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = call i32 @fclose(i32* %5)
br label %36
20: ; preds = %7
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %5, i64 0, i32 %21)
%23 = call i32 @fread(i8* %16, i64 %10, i32 1, i32* %5)
%24 = call i32 @fclose(i32* %5)
%25 = icmp sgt i64 %10, 0
br i1 %25, label %26, label %34
26: ; preds = %20, %26
%27 = phi i64 [ %32, %26 ], [ 0, %20 ]
%28 = getelementptr inbounds i8, i8* %16, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 @putchar(i32 %30)
%32 = add nuw nsw i64 %27, 1
%33 = icmp eq i64 %32, %10
br i1 %33, label %34, label %26
34: ; preds = %26, %20
%35 = call i32 @free(i8* %16)
br label %36
36: ; preds = %2, %34, %18
ret void
}