#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*/ *fopen(char const *, char *);
scalar_t__ gen_check_sum_code(char const *, char const *);
int /*<<< orphan*/ puts(char *);
int main(int argc, const char **argv) {
  int result;
  FILE *dst_file = NULL;
  FILE *src_file = NULL;
  src_file = fopen(argv[1], "rb+");
  if (src_file) {
    puts("Source file is open");
    fclose(src_file);
    dst_file = fopen(argv[2], "wb+");
    if (dst_file) {
      puts("Destination file is created.");
      fclose(dst_file);
      if (gen_check_sum_code(argv[1], argv[2]))
        puts("Open file failed.");
      else
        puts("Everything is ok.");
      result = 0;
    } else {
      puts("can't create destination file.");
      result = -1;
    }
  } else {
    puts("can't open source file");
    result = -1;
  }
  return result;
}


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)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1236 <main+0xf6>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     121e <main+0xde>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <gen_check_sum_code@plt>
cmp    $0x0,%rax
je     1206 <main+0xc6>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
jmp    1212 <main+0xd2>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x14(%rbp)
jmp    1231 <main+0xf1>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    1249 <main+0x109>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11cc <main+0x8c>
mov    %rax,%rbp
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x10(%rbx),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d5 <main+0x95>
mov    %rax,%rbp
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1050 <gen_check_sum_code@plt>
test   %rax,%rax
lea    0xe8f(%rip),%rax
lea    0xe76(%rip),%rdi
cmove  %rax,%rdi
xor    %r14d,%r14d
jmp    11dc <main+0x9c>
lea    0xea9(%rip),%rdi
jmp    11dc <main+0x9c>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [20 x i8] c"Source file is open\00"
@.str.2 = [4 x i8] c"wb+\00"
@.str.3 = [29 x i8] c"Destination file is created.\00"
@.str.4 = [18 x i8] c"Open file failed.\00"
@.str.5 = [18 x i8] c"Everything is ok.\00"
@.str.6 = [31 x i8] c"can't create destination file.\00"
@.str.7 = [23 x i8] c"can't open source file\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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
store i32* null, i32** %8
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %45
15: ; preds = %2
%16 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32*, i32** %8
%18 = call i32 @fclose(i32* %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %42
25: ; preds = %15
%26 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @gen_check_sum_code(i8* %31, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %41
39: ; preds = %25
%40 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
store i32 0, i32* %6
br label %44
42: ; preds = %15
%43 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %6
br label %44
44: ; preds = %42, %41
br label %47
45: ; preds = %2
%46 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %6
br label %47
47: ; preds = %45, %44
%48 = load i32, i32* %6
ret i32 %48
}

LLVM IR (-O2):
@.str = [4 x i8] c"rb+\00"
@.str.1 = [20 x i8] c"Source file is open\00"
@.str.2 = [4 x i8] c"wb+\00"
@.str.3 = [29 x i8] c"Destination file is created.\00"
@.str.4 = [18 x i8] c"Open file failed.\00"
@.str.5 = [18 x i8] c"Everything is ok.\00"
@.str.6 = [31 x i8] c"can't create destination file.\00"
@.str.7 = [23 x i8] c"can't open source file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @fclose(i32* %5)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %22, label %14
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @fclose(i32* %12)
%17 = load i8*, i8** %3
%18 = load i8*, i8** %10
%19 = tail call i64 @gen_check_sum_code(i8* %17, i8* %18)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0)
br label %22
22: ; preds = %2, %7, %14
%23 = phi i8* [ %21, %14 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), %7 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), %2 ]
%24 = phi i32 [ 0, %14 ], [ -1, %7 ], [ -1, %2 ]
%25 = tail call i32 @puts(i8* dereferenceable(1) %23)
ret i32 %24
}