#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ftruncate(int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s old_file new_file\n", argv[0]);
    return (EXIT_FAILURE);
  }
  char *old_fi_name;
  char *new_fi_name;
  int old_file;
  int new_file;
  off_t old_fi_size = 0;
  struct stat old_fi_stats;
  old_fi_name = argv[1];
  new_fi_name = argv[2];
  if ((old_file = open(old_fi_name, O_RDONLY)) == -1) {
    perror(old_fi_name);
    return EXIT_FAILURE;
  }
  stat(old_fi_name, &old_fi_stats);
  old_fi_size = old_fi_stats.st_size;
  if ((new_file = open(new_fi_name, O_RDWR | O_CREAT, old_fi_stats.st_mode)) ==
      -1) {
    perror(new_fi_name);
    return EXIT_FAILURE;
  }
  if (ftruncate(new_file, old_fi_size) == -1) {
    perror(new_fi_name);
    return EXIT_FAILURE;
  }
  if (close(old_file) == -1) {
    perror(old_fi_name);
    return EXIT_FAILURE;
  }
  if (close(new_file) == -1) {
    perror(new_fi_name);
    return EXIT_FAILURE;
  }
  printf("Size of old file (%s): %li bytes\n", old_fi_name, old_fi_size);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bd <main+0x4d>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <main+0x1a2>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1216 <main+0xa6>
mov    -0x18(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2dbb(%rip),%rax
or     (%rax),%esi
mov    -0x38(%rbp),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    126f <main+0xff>
mov    -0x20(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    129d <main+0x12d>
mov    -0x20(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    12c8 <main+0x158>
mov    -0x18(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    12f3 <main+0x183>
mov    -0x20(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xd1c(%rip),%rdi
call   1030 <printf@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jg     119e <main+0x2e>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe6c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    124c <main+0xdc>
mov    0x8(%rsi),%r12
mov    0x10(%rsi),%r14
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1244 <main+0xd4>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1070 <stat@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%r15d
mov    0x2dff(%rip),%rax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     123f <main+0xcf>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15d,%esi
call   1040 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     123f <main+0xcf>
mov    %ebp,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1244 <main+0xd4>
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     123f <main+0xcf>
lea    0xdf2(%rip),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <printf@plt>
mov    0x2d7b(%rip),%rax
jmp    1253 <main+0xe3>
mov    %r14,%rdi
jmp    1247 <main+0xd7>
mov    %r12,%rdi
call   1090 <perror@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s old_file new_file\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [34 x i8] c"Size of old file (%s): %li bytes\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %3
br label %83
21: ; preds = %2
store i32 0, i32* %10
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %6
%29 = load i32, i32* @O_RDONLY
%30 = call i32 (i8*, i32, ...) @open(i8* %28, i32 %29)
store i32 %30, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %21
%33 = load i8*, i8** %6
%34 = call i32 @perror(i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %83
36: ; preds = %21
%37 = load i8*, i8** %6
%38 = call i32 @stat(i8* %37, %struct.stat* %11)
%39 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%40 = load i32, i32* %39
store i32 %40, i32* %10
%41 = load i8*, i8** %7
%42 = load i32, i32* @O_RDWR
%43 = load i32, i32* @O_CREAT
%44 = or i32 %42, %43
%45 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 (i8*, i32, ...) @open(i8* %41, i32 %44, i32 %46)
store i32 %47, i32* %9
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %36
%50 = load i8*, i8** %7
%51 = call i32 @perror(i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
store i32 %52, i32* %3
br label %83
53: ; preds = %36
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = call i32 @ftruncate(i32 %54, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i8*, i8** %7
%60 = call i32 @perror(i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %83
62: ; preds = %53
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i8*, i8** %6
%68 = call i32 @perror(i8* %67)
%69 = load i32, i32* @EXIT_FAILURE
store i32 %69, i32* %3
br label %83
70: ; preds = %62
%71 = load i32, i32* %9
%72 = call i32 @close(i32 %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %78
74: ; preds = %70
%75 = load i8*, i8** %7
%76 = call i32 @perror(i8* %75)
%77 = load i32, i32* @EXIT_FAILURE
store i32 %77, i32* %3
br label %83
78: ; preds = %70
%79 = load i8*, i8** %6
%80 = load i32, i32* %10
%81 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %79, i32 %80)
%82 = load i32, i32* @EXIT_SUCCESS
store i32 %82, i32* %3
br label %83
83: ; preds = %78, %74, %66, %58, %49, %32, %14
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s old_file new_file\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [34 x i8] c"Size of old file (%s): %li bytes\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
br label %54
10: ; preds = %2
%11 = bitcast %struct.stat* %3 to i8*
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 (i8*, i32, ...) @open(i8* %13, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = tail call i32 @perror(i8* %13)
br label %51
21: ; preds = %10
%22 = call i32 @stat(i8* %13, %struct.stat* %3)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%24 = load i32, i32* %23
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_CREAT
%27 = or i32 %26, %25
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, i32, ...) @open(i8* %15, i32 %27, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = tail call i32 @perror(i8* %15)
br label %51
34: ; preds = %21
%35 = tail call i32 @ftruncate(i32 %30, i32 %24)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = tail call i32 @perror(i8* %15)
br label %51
39: ; preds = %34
%40 = tail call i32 @close(i32 %17)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = tail call i32 @perror(i8* %13)
br label %51
44: ; preds = %39
%45 = tail call i32 @close(i32 %30)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = tail call i32 @perror(i8* %15)
br label %51
49: ; preds = %44
%50 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %24)
br label %51
51: ; preds = %49, %47, %42, %37, %32, %19
%52 = phi i32* [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %32 ], [ @EXIT_FAILURE, %37 ], [ @EXIT_FAILURE, %42 ], [ @EXIT_FAILURE, %47 ], [ @EXIT_SUCCESS, %49 ]
%53 = load i32, i32* %52
br label %54
54: ; preds = %51, %5
%55 = phi i32 [ %9, %5 ], [ %53, %51 ]
ret i32 %55
}