#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*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int main(void) {
  FILE *src, *dst;
  char buf[256];
  if ((src = fopen("infile.txt", "r")) == NULL) {
    perror("Error");
    exit(1);
  }
  if ((dst = fopen("outfile.txt", "w")) == NULL) {
    perror("Error");
    exit(2);
  }
  while ((fgets(buf, 256 - 1, src)) != NULL) {
    fputs(buf, dst);
  }
  fclose(src);
  fclose(dst);
  perror("Error");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a9 <main+0x49>
lea    0xe71(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe61(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e0 <main+0x80>
lea    0xe3a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
jmp    11e5 <main+0x85>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1219 <main+0xb9>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
jmp    11e5 <main+0x85>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdd9(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe8d(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    119a <main+0x3a>
lea    0xe80(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%r14
lea    0xe6d(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11cb <main+0x6b>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1210 <main+0xb0>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11f0 <main+0x90>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xde4(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"infile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [12 x i8] c"outfile.txt\00"
@.str.4 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [256 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %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** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %10
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = load i32*, i32** %2
%20 = call i32* @fgets(i8* %18, i32 255, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = load i32*, i32** %3
%25 = call i32 @fputs(i8* %23, i32* %24)
br label %17
26: ; preds = %17
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"infile.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [12 x i8] c"outfile.txt\00"
@.str.4 = [2 x i8] c"w\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 ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = 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))
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i32* @fgets(i8* %2, i32 255, i32* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %21, label %17
14: ; preds = %8
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 2)
unreachable
17: ; preds = %11, %17
%18 = call i32 @fputs(i8* %2, i32* %9)
%19 = call i32* @fgets(i8* %2, i32 255, i32* %3)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %17
21: ; preds = %17, %11
%22 = call i32 @fclose(i32* %3)
%23 = call i32 @fclose(i32* %9)
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
}