#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*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void file_move(char *src1, char *dst1) {
  FILE *from = fopen(src1, "r");
  FILE *to = fopen(dst1, "w");
  printf("from %s to %s\n", src1, dst1);
  char ch;
  while (!feof(from)) {
    ch = fgetc(from);
    printf("%c", ch);
    if (ferror(from)) {
      printf("Error reading source file.\n");
      exit(1);
    }
    if (!feof(from))
      fputc(ch, to);
    if (ferror(to)) {
      printf("Error writing destination file.\n");
      exit(1);
    }
  }
  fclose(from);
  fclose(to);
}


x86 assembly (clang, -O0):
<file_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ec <file_move+0x6c>
jmp    1286 <file_move+0x106>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1235 <file_move+0xb5>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
jne    1256 <file_move+0xd6>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1281 <file_move+0x101>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11ce <file_move+0x4e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_move>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe4c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe3f(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
lea    0xe2f(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11fd <file_move+0x5d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    125a <file_move+0xba>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1240 <file_move+0xa0>
mov    %rbx,%rdi
call   1080 <fgetc@plt>
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    1263 <file_move+0xc3>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    11f0 <file_move+0x50>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
jmp    11f0 <file_move+0x50>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fclose@plt>
lea    0xdb2(%rip),%rdi
jmp    126a <file_move+0xca>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"from %s to %s\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [28 x i8] c"Error reading source file.\0A\00"
@.str.5 = [33 x i8] c"Error writing destination file.\0A\00"
define void @file_move(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %12, i8* %13)
br label %15
15: ; preds = %47, %2
%16 = load i32*, i32** %5
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %48
20: ; preds = %15
%21 = load i32*, i32** %5
%22 = call signext i8 @fgetc(i32* %21)
store i8 %22, i8* %7
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %5
%27 = call i64 @ferror(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = load i32*, i32** %5
%34 = call i32 @feof(i32* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i8, i8* %7
%38 = load i32*, i32** %6
%39 = call i32 @fputc(i8 signext %37, i32* %38)
br label %40
40: ; preds = %36, %32
%41 = load i32*, i32** %6
%42 = call i64 @ferror(i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %40
br label %15
48: ; preds = %15
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"from %s to %s\0A\00"
@str = [32 x i8] c"Error writing destination file.\00"
@str.6 = [27 x i8] c"Error reading source file.\00"
define void @file_move(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %6
6: ; preds = %23, %2
%7 = tail call i32 @feof(i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = tail call signext i8 @fgetc(i32* %3)
%11 = sext i8 %10 to i32
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call i64 @ferror(i32* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = tail call i32 @feof(i32* %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @fputc(i8 signext %10, i32* %4)
br label %23
23: ; preds = %21, %18
%24 = tail call i64 @ferror(i32* %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %6, label %26
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %6
%30 = tail call i32 @fclose(i32* %3)
%31 = tail call i32 @fclose(i32* %4)
ret void
}