#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(void) {
  char line[100];
  fgets(line, 100, stdin);
  printf("%s", line);
  fgets(line, 100, stdin);
  printf("%s", line);
  fgets(line, 100, stdin);
  printf("%s", line);
  close(0);
  int fd = open("/etc/passwd", O_RDONLY);
  if (fd != 0) {
    fprintf(stderr, "Could not open data as fd 0\n");
    exit(EXIT_FAILURE);
  }
  fgets(line, 100, stdin);
  printf("%s", line);
  fgets(line, 100, stdin);
  printf("%s", line);
  fgets(line, 100, stdin);
  printf("%s", line);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    0xe05(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     1233 <main+0xd3>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xdab(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xd84(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2d54(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rsi
lea    0xd5d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    0x2e70(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xe76(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
jne    1259 <main+0xf9>
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xdfb(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [29 x i8] c"Could not open data as fd 0\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 100, i32 %5)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 100, i32 %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 100, i32 %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @close(i32 0)
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %0
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %0
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %30, i32 100, i32 %31)
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %35, i32 100, i32 %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %40, i32 100, i32 %41)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [29 x i8] c"Could not open data as fd 0\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 100, i32 %3)
%5 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %2, i32 100, i32 %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %2, i32 100, i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%12 = call i32 @close(i32 0)
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %0
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %0
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %2, i32 100, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %2, i32 100, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %2, i32 100, i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}