#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  char s[256];
  FILE *i = fopen("input", "r");
  FILE *o = fopen("output", "w");
  if (i == NULL || o == NULL) {
    exit(-1);
  }
  while (fgets(s, 256, i) != NULL) {
    printf("%s", s);
  }
  fprintf(o, "hogehoge");
  fclose(i);
  fclose(o);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
lea    0xe75(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11c2 <main+0x62>
cmpq   $0x0,-0x120(%rbp)
jne    11cc <main+0x6c>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11d1 <main+0x71>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120b <main+0xab>
lea    -0x110(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
jmp    11d1 <main+0x71>
mov    -0x120(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x120(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe7d(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
test   %r12,%r12
je     122a <main+0xca>
mov    %rax,%r14
test   %rax,%rax
je     122a <main+0xca>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f0 <main+0x90>
lea    0xe49(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x70>
lea    0xe1d(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"output\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [9 x i8] c"hogehoge\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9, %0
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %9
br label %15
15: ; preds = %20, %14
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i32* @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %15
23: ; preds = %15
%24 = load i32*, i32** %4
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32*, i32** %3
%27 = call i32 @fclose(i32* %26)
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"output\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [9 x i8] c"hogehoge\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %3, null
%6 = icmp eq i32* %4, null
%7 = or i1 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %13
11: ; preds = %0
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %8, %13
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%15 = call i32* @fgets(i8* %2, i32 256, i32* %3)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %8
%18 = call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i64 8, i64 1, i32* %4)
%19 = call i32 @fclose(i32* %3)
%20 = call i32 @fclose(i32* %4)
ret i32 0
}