#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *fp = NULL;
  char buf[1024];
  printf("Content-type:text/html\r\n\r\n");
  printf(
      "<html><head><title>USERINFO</title>                <meta "
      "http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>");
  printf("<body><div width=900px><div align=center>                "
         "<h1>USERINFO</h1></div><hr> <div>");
  if ((fp = fopen("/etc/passwd", "r")) == NULL) {
    printf("no users or can not open!\n");
    return -1;
  }
  do {
    if (fgets(buf, sizeof(buf), fp))
      printf("%s <br>", buf);
  } while (feof(fp) == 0);
  printf("</div><hr></div></body></html>\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf53(%rip),%rdi
lea    0xf58(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d6 <main+0x86>
lea    0xf40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1245 <main+0xf5>
jmp    11db <main+0x8b>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120f <main+0xbf>
lea    -0x420(%rbp),%rsi
lea    0xf16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1214 <main+0xc4>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11db <main+0x8b>
lea    0xef8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xf7d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf3f(%rip),%rdi
lea    0xf44(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1209 <main+0xa9>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xf2f(%rip),%r15
jmp    11cd <main+0x6d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11f1 <main+0x91>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c0 <main+0x60>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    121a <main+0xba>
lea    0xf19(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Content-type:text/html\0D\0A\0D\0A\00"
@.str.1 = [127 x i8] c"<html><head><title>USERINFO</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>\00"
@.str.2 = [91 x i8] c"<body><div width=900px><div align=center> <h1>USERINFO</h1></div><hr> <div>\00"
@.str.3 = [12 x i8] c"/etc/passwd\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [27 x i8] c"no users or can not open!\0A\00"
@.str.6 = [8 x i8] c"%s <br>\00"
@.str.7 = [32 x i8] c"</div><hr></div></body></html>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %33
15: ; preds = %2
br label %16
16: ; preds = %25, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i64 @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %16
br label %25
25: ; preds = %24
%26 = load i32*, i32** %6
%27 = call i64 @feof(i32* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %16, label %29
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %29, %13
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [127 x i8] c"<html><head><title>USERINFO</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/></head>\00"
@.str.2 = [91 x i8] c"<body><div width=900px><div align=center> <h1>USERINFO</h1></div><hr> <div>\00"
@.str.3 = [12 x i8] c"/etc/passwd\00"
@.str.4 = [2 x i8] c"r\00"
@.str.6 = [8 x i8] c"%s <br>\00"
@str = [26 x i8] c"Content-type:text/html\0D\0A\0D\00"
@str.8 = [31 x i8] c"</div><hr></div></body></html>\00"
@str.9 = [26 x i8] c"no users or can not open!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([127 x i8], [127 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
br label %23
12: ; preds = %2, %17
%13 = call i64 @fgets(i8* %4, i32 1024, i32* %8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %17
17: ; preds = %12, %15
%18 = call i64 @feof(i32* %8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %12, label %20
20: ; preds = %17
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
%22 = call i32 @fclose(i32* %8)
br label %23
23: ; preds = %20, %10
%24 = phi i32 [ -1, %10 ], [ 0, %20 ]
ret i32 %24
}