#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
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*/ printf(char *);
int stat(char *, struct stat *);
void process_404(FILE *client_write) {
  char *path_404 = "webapps/404.html";
  struct stat st;
  char buf[1024];
  if (stat(path_404, &st) == -1) {
    fputs("404 Page!", client_write);
    fflush(client_write);
    fclose(client_write);
    return;
  }
  FILE *file_404 = fopen(path_404, "r");
  fgets(buf, sizeof(buf), file_404);
  while (!feof(file_404)) {
    fputs(buf, client_write);
    fgets(buf, sizeof(buf), file_404);
  }
  printf("404-3\n");
  fflush(client_write);
  fclose(client_write);
  fclose(file_404);
}


x86 assembly (clang, -O0):
<process_404>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    11d7 <process_404+0x57>
mov    -0x8(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
jmp    127e <process_404+0xfe>
mov    -0x10(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0x428(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1227 <process_404+0xa7>
jmp    1254 <process_404+0xd4>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <fputs@plt>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
jmp    1206 <process_404+0x86>
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_404>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%r14
lea    0xe5a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     1258 <process_404+0xc8>
lea    0xe40(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1227 <process_404+0x97>
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1200 <process_404+0x70>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1090 <fflush@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdb2(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
call   1090 <fflush@plt>
mov    %r14,%rdi
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"webapps/404.html\00"
@.str.1 = [10 x i8] c"404 Page!\00"
@.str.2 = [2 x i8] c"r\00"
@str = [6 x i8] c"404-3\00"
define void @process_404(i32* nocapture %0) {
%2 = alloca %struct.stat
%3 = alloca [1024 x i8]
%4 = bitcast %struct.stat* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @stat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 9, i64 1, i32* %0)
%10 = tail call i32 @fflush(i32* %0)
%11 = tail call i32 @fclose(i32* %0)
br label %27
12: ; preds = %1
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @fgets(i8* %5, i32 1024, i32* %13)
%15 = call i32 @feof(i32* %13)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12, %17
%18 = call i32 @fputs(i8* %5, i32* %0)
%19 = call i32 @fgets(i8* %5, i32 1024, i32* %13)
%20 = call i32 @feof(i32* %13)
%21 = icmp eq i32 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %12
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%24 = call i32 @fflush(i32* %0)
%25 = call i32 @fclose(i32* %0)
%26 = call i32 @fclose(i32* %13)
br label %27
27: ; preds = %22, %8
ret void
}