#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*/ work;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int args, char *argv[]) {
  FILE *fp;
  FILE *fp_save;
  char work[0x100];
  if (args < 3) {
    printf("File name is not specified");
    return (-1);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    printf("\nFailed to open %s!", argv[1]);
    return (-1);
  }
  if ((fp_save = fopen(argv[2], "w")) == NULL) {
    printf("\nFailed to open %s!", argv[2]);
    fclose(fp);
    return (-1);
  }
  while (fgets(work, sizeof(work), fp) != NULL) {
    fprintf(fp_save, "%s", work);
    fflush(fp_save);
  }
  fclose(fp);
  fclose(fp_save);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119d <main+0x3d>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    122e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <main+0x130>
jmp    1233 <main+0xd3>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1277 <main+0x117>
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xdcf(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fflush@plt>
jmp    1233 <main+0xd3>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jg     1184 <main+0x24>
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    123a <main+0xda>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     120c <main+0xac>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1220 <main+0xc0>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f8 <main+0x98>
mov    %rsp,%r15
nop
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    123f <main+0xdf>
mov    0x8(%r15),%rsi
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    123a <main+0xda>
mov    0x10(%r15),%rsi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"File name is not specified\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"\0AFailed to open %s!\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %54
24: ; preds = %13
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
store i32 -1, i32* %3
br label %54
37: ; preds = %24
br label %38
38: ; preds = %43, %37
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%40 = load i32*, i32** %6
%41 = call i32* @fgets(i8* %39, i32 256, i32* %40)
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32*, i32** %7
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%46 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fflush(i32* %47)
br label %38
49: ; preds = %38
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
%52 = load i32*, i32** %7
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %49, %30, %19, %11
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [27 x i8] c"File name is not specified\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"\0AFailed to open %s!\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %36
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %36
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = call i32* @fgets(i8* %4, i32 256, i32* %11)
%23 = icmp eq i32* %22, null
br i1 %23, label %33, label %28
24: ; preds = %16
%25 = load i8*, i8** %17
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = tail call i32 @fclose(i32* %11)
br label %36
28: ; preds = %21, %28
%29 = call i32 @fputs(i8* %4, i32* %19)
%30 = call i32 @fflush(i32* %19)
%31 = call i32* @fgets(i8* %4, i32 256, i32* %11)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %28
33: ; preds = %28, %21
%34 = call i32 @fclose(i32* %11)
%35 = call i32 @fclose(i32* %19)
br label %36
36: ; preds = %33, %24, %13, %6
%37 = phi i32 [ -1, %6 ], [ -1, %13 ], [ -1, %24 ], [ 0, %33 ]
ret i32 %37
}