#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp1, *fp2;
  char ch[5];
  if (argc != 3) {
    printf("command error!\n");
    return -1;
  }
  if ((fp1 = fopen(argv[1], "r")) == NULL) {
    printf("file %s cannot open ", argv[1]);
    return -1;
  }
  if ((fp2 = fopen(argv[2], "wb+")) == NULL) {
    printf("cannot create file %s", argv[1]);
    return -1;
  }
  while (fgets(ch, 5, fp1) != NULL) {
    fputs(ch, fp2);
  }
  fclose(fp1);
  fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ce <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1212 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125e <main+0x10e>
jmp    1217 <main+0xc7>
lea    -0x25(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x5,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1245 <main+0xf5>
lea    -0x25(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1217 <main+0xc7>
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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11f4 <main+0x94>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rax,%r12
mov    0x10(%r15),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     120f <main+0xaf>
mov    %rax,%r14
lea    0x3(%rsp),%rdi
mov    $0x5,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x80>
lea    0x3(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1226 <main+0xc6>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
jmp    1221 <main+0xc1>
mov    0x8(%r15),%rsi
lea    0xdf5(%rip),%rdi
jmp    121a <main+0xba>
mov    0x8(%r15),%rsi
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"command error!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"file %s cannot open \00"
@.str.3 = [4 x i8] c"wb+\00"
@.str.4 = [22 x i8] c"cannot create file %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 [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %50
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 ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %50
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 ([4 x i8], [4 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 %35
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %33)
store i32 -1, i32* %3
br label %50
35: ; preds = %24
br label %36
36: ; preds = %41, %35
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%38 = load i32*, i32** %6
%39 = call i32* @fgets(i8* %37, i32 5, i32* %38)
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%43 = load i32*, i32** %7
%44 = call i32 @fputs(i8* %42, i32* %43)
br label %36
45: ; preds = %36
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %7
%49 = call i32 @fclose(i32* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %45, %30, %19, %11
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"file %s cannot open \00"
@.str.3 = [4 x i8] c"wb+\00"
@.str.4 = [22 x i8] c"cannot create file %s\00"
@str = [15 x i8] c"command error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %34
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 ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %34
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 ([4 x i8], [4 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 5, i32* %11)
%23 = icmp eq i32* %22, null
br i1 %23, label %31, label %27
24: ; preds = %16
%25 = load i8*, i8** %9
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %34
27: ; preds = %21, %27
%28 = call i32 @fputs(i8* %4, i32* %19)
%29 = call i32* @fgets(i8* %4, i32 5, i32* %11)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %27
31: ; preds = %27, %21
%32 = call i32 @fclose(i32* %11)
%33 = call i32 @fclose(i32* %19)
br label %34
34: ; preds = %31, %24, %13, %6
%35 = phi i32 [ -1, %6 ], [ -1, %13 ], [ -1, %24 ], [ 0, %31 ]
ret i32 %35
}