#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fsync(int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  FILE *from, *to;
  char buff[4096];
  if (argc != 3) {
    printf("Usage: crossepg_epgcopy <source> <destination>\n");
    return 1;
  }
  if ((from = fopen(argv[1], "rb")) == NULL) {
    printf("Cannot open source file.\n");
    return 1;
  }
  unlink(argv[2]);
  if ((to = fopen(argv[2], "wb")) == NULL) {
    printf("Cannot open destination file.\n");
    return 1;
  }
  fseek(from, 0, SEEK_END);
  if (ftell(from) < 21) {
    printf("%s is not valid", argv[1]);
    return 0;
  }
  memset(buff, 0, 17);
  fwrite(buff, 17, 1, to);
  fseek(from, 17, SEEK_SET);
  while (!feof(from)) {
    int size = fread(buff, 1, 4096, from);
    if (size > 0)
      fwrite(buff, size, 1, to);
  }
  fsync(fileno(to));
  fseek(from, 0, SEEK_SET);
  fseek(to, 0, SEEK_SET);
  fread(buff, 17, 1, from);
  fwrite(buff, 17, 1, to);
  fclose(from);
  fclose(to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11fd <main+0x3d>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13fe <main+0x23e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe24(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1239 <main+0x79>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13fe <main+0x23e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf8(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1282 <main+0xc2>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13fe <main+0x23e>
mov    -0x18(%rbp),%rdi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
cmp    $0x15,%eax
jge    12ca <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13fe <main+0x23e>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1070 <memset@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x11,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
mov    $0x11,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    132c <main+0x16c>
jmp    1379 <main+0x1b9>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
jle    1374 <main+0x1b4>
lea    -0x1020(%rbp),%rdi
mov    -0x1024(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   10e0 <fwrite@plt>
jmp    130e <main+0x14e>
mov    -0x20(%rbp),%rdi
call   10a0 <fileno@plt>
mov    %eax,%edi
call   10c0 <fsync@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c44(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c30(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x11,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x11,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
cmp    $0x3,%edi
jne    1257 <main+0x87>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe0e(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1260 <main+0x90>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x10(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1269 <main+0x99>
mov    %rax,%r14
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
cmp    $0x14,%eax
jg     128e <main+0xbe>
mov    0x8(%rbp),%rsi
lea    0xdb8(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    127b <main+0xab>
lea    0xdef(%rip),%rdi
jmp    1270 <main+0xa0>
lea    0xdcd(%rip),%rdi
jmp    1270 <main+0xa0>
lea    0xda6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbp
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10f0 <fwrite@plt>
mov    0x2d19(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x11,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1349 <main+0x179>
mov    %r14,%rdi
call   10b0 <fileno@plt>
mov    %eax,%edi
call   10d0 <fsync@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10f0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
jmp    127b <main+0xab>
mov    %rsp,%rbp
jmp    135c <main+0x18c>
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    12dc <main+0x10c>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    1350 <main+0x180>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10f0 <fwrite@plt>
jmp    1350 <main+0x180>

LLVM IR (-O0):
@.str = [48 x i8] c"Usage: crossepg_epgcopy <source> <destination>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [26 x i8] c"Cannot open source file.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [31 x i8] c"Cannot open destination file.\0A\00"
@SEEK_END = global i32 0
@.str.5 = [16 x i8] c"%s is not valid\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [4096 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %92
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %92
22: ; preds = %14
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @unlink(i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %92
34: ; preds = %22
%35 = load i32*, i32** %6
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %6
%39 = call i32 @ftell(i32* %38)
%40 = icmp slt i32 %39, 21
br i1 %40, label %41, label %46
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %44)
store i32 0, i32* %3
br label %92
46: ; preds = %34
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%48 = call i32 @memset(i8* %47, i32 0, i32 17)
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%50 = load i32*, i32** %7
%51 = call i32 @fwrite(i8* %49, i32 17, i32 1, i32* %50)
%52 = load i32*, i32** %6
%53 = load i32, i32* @SEEK_SET
%54 = call i32 @fseek(i32* %52, i32 17, i32 %53)
br label %55
55: ; preds = %71, %46
%56 = load i32*, i32** %6
%57 = call i32 @feof(i32* %56)
%58 = icmp ne i32 %57, 0
%59 = xor i1 %58, true
br i1 %59, label %60, label %72
60: ; preds = %55
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%62 = load i32*, i32** %6
%63 = call i32 @fread(i8* %61, i32 1, i32 4096, i32* %62)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %60
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%68 = load i32, i32* %9
%69 = load i32*, i32** %7
%70 = call i32 @fwrite(i8* %67, i32 %68, i32 1, i32* %69)
br label %71
71: ; preds = %66, %60
br label %55
72: ; preds = %55
%73 = load i32*, i32** %7
%74 = call i32 @fileno(i32* %73)
%75 = call i32 @fsync(i32 %74)
%76 = load i32*, i32** %6
%77 = load i32, i32* @SEEK_SET
%78 = call i32 @fseek(i32* %76, i32 0, i32 %77)
%79 = load i32*, i32** %7
%80 = load i32, i32* @SEEK_SET
%81 = call i32 @fseek(i32* %79, i32 0, i32 %80)
%82 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%83 = load i32*, i32** %6
%84 = call i32 @fread(i8* %82, i32 17, i32 1, i32* %83)
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%86 = load i32*, i32** %7
%87 = call i32 @fwrite(i8* %85, i32 17, i32 1, i32* %86)
%88 = load i32*, i32** %6
%89 = call i32 @fclose(i32* %88)
%90 = load i32*, i32** %7
%91 = call i32 @fclose(i32* %90)
store i32 0, i32* %3
br label %92
92: ; preds = %72, %41, %32, %20, %12
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@.str.5 = [16 x i8] c"%s is not valid\00"
@SEEK_SET = global i32 0
@str = [30 x i8] c"Cannot open destination file.\00"
@str.6 = [25 x i8] c"Cannot open source file.\00"
@str.7 = [47 x i8] c"Usage: crossepg_epgcopy <source> <destination>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 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 ([47 x i8], [47 x i8]* @str.7, i64 0, i64 0))
br label %58
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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %58
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @unlink(i8* %17)
%19 = load i8*, i8** %16
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %58
24: ; preds = %15
%25 = load i32, i32* @SEEK_END
%26 = tail call i32 @fseek(i32* %11, i32 0, i32 %25)
%27 = tail call i32 @ftell(i32* %11)
%28 = icmp slt i32 %27, 21
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %9
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %30)
br label %58
32: ; preds = %24
%33 = call i32 @memset(i8* %4, i32 0, i32 17)
%34 = call i32 @fwrite(i8* %4, i32 17, i32 1, i32* %20)
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %11, i32 17, i32 %35)
%37 = call i32 @feof(i32* %11)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %32, %44
%40 = call i32 @fread(i8* %4, i32 1, i32 4096, i32* %11)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @fwrite(i8* %4, i32 %40, i32 1, i32* %20)
br label %44
44: ; preds = %42, %39
%45 = call i32 @feof(i32* %11)
%46 = icmp eq i32 %45, 0
br i1 %46, label %39, label %47
47: ; preds = %44, %32
%48 = call i32 @fileno(i32* %20)
%49 = call i32 @fsync(i32 %48)
%50 = load i32, i32* @SEEK_SET
%51 = call i32 @fseek(i32* %11, i32 0, i32 %50)
%52 = load i32, i32* @SEEK_SET
%53 = call i32 @fseek(i32* %20, i32 0, i32 %52)
%54 = call i32 @fread(i8* %4, i32 17, i32 1, i32* %11)
%55 = call i32 @fwrite(i8* %4, i32 17, i32 1, i32* %20)
%56 = call i32 @fclose(i32* %11)
%57 = call i32 @fclose(i32* %20)
br label %58
58: ; preds = %47, %29, %22, %13, %6
%59 = phi i32 [ 1, %6 ], [ 1, %13 ], [ 1, %22 ], [ 0, %29 ], [ 0, %47 ]
ret i32 %59
}