#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 EOF;
int /*<<< orphan*/ GetFilPathForThumbnaleByDocID(char *, unsigned int);
unsigned int atol(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int main() {
  char FilePath[255];
  unsigned int DocID;
  FILE *Thumbnale;
  char buff[6144];
  int c;
  if (getenv("QUERY_STRING") == NULL) {
    printf("Content-type: text/html\n\n");
    printf("No DocID\n");
    exit(1);
  }
  DocID = atol(getenv("QUERY_STRING"));
  GetFilPathForThumbnaleByDocID(FilePath, DocID);
  if ((Thumbnale = fopen(FilePath, "rb")) == NULL) {
    printf("Content-type: text/html\n\n");
    perror(FilePath);
    exit(1);
  }
  printf("Content-type: image/jpeg\n\n");
  while ((c = getc(Thumbnale)) != EOF) {
    putchar(c);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1930,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    11da <main+0x4a>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <atol@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%esi
call   1060 <GetFilPathForThumbnaleByDocID@plt>
lea    -0x110(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
jne    124c <main+0xbc>
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x120(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x1924(%rbp)
mov    0x2d77(%rip),%rcx
cmp    (%rcx),%eax
je     1289 <main+0xf9>
mov    -0x1924(%rbp),%edi
call   1040 <putchar@plt>
jmp    1258 <main+0xc8>
mov    -0x4(%rbp),%eax
add    $0x1930,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1221 <main+0x91>
mov    %rax,%rdi
call   1070 <atol@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <GetFilPathForThumbnaleByDocID@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1243 <main+0xb3>
mov    %rax,%rbx
lea    0xe32(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    0x2df6(%rip),%r14
cmp    (%r14),%eax
je     1214 <main+0x84>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    (%r14),%eax
jne    1200 <main+0x70>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe02(%rip),%rdi
call   1050 <puts@plt>
lea    0xe0f(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xde0(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [26 x i8] c"Content-type: text/html\0A\0A\00"
@.str.2 = [10 x i8] c"No DocID\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [27 x i8] c"Content-type: image/jpeg\0A\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [6144 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @atol(i32* %14)
store i32 %15, i32* %3
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 @GetFilPathForThumbnaleByDocID(i8* %16, i32 %17)
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %20, i32** %4
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%25 = call i32 @perror(i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %13
%28 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %34, %27
%30 = load i32*, i32** %4
%31 = call i32 @getc(i32* %30)
store i32 %31, i32* %6
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* %6
%36 = call i32 @putchar(i32 %35)
br label %29
37: ; preds = %29
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.3 = [3 x i8] c"rb\00"
@EOF = global i32 0
@str = [26 x i8] c"Content-type: image/jpeg\0A\00"
@str.6 = [25 x i8] c"Content-type: text/html\0A\00"
@str.7 = [9 x i8] c"No DocID\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @atol(i32* %3)
%11 = call i32 @GetFilPathForThumbnaleByDocID(i8* %2, i32 %10)
%12 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%16 = call i32 @perror(i8* %2)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%20 = call i32 @getc(i32* %12)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %18, %23
%24 = phi i32 [ %26, %23 ], [ %20, %18 ]
%25 = call i32 @putchar(i32 %24)
%26 = call i32 @getc(i32* %12)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %23
29: ; preds = %23, %18
ret i32 0
}