#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 */
char EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ log_wrapper(int /*<<< orphan*/ *, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char ch = EOF;
  char dest_buf[100];
  FILE *source, *logf;
  int target = -1;
  if (argc != 2) {
    printf("Usage: %s filename\n", argv[0]);
  }
  logf = fopen("./backups/.log", "w");
  if (logf == NULL) {
    printf("ERROR: Failed to open %s\n", "./backups/.log");
    exit(EXIT_FAILURE);
  }
  log_wrapper(logf, "Starting back up: ", argv[1]);
  source = fopen(argv[1], "r");
  if (source == NULL) {
    printf("ERROR: Failed to open %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  strcpy(dest_buf, "./backups/");
  strncat(dest_buf, argv[1], 100 - strlen(dest_buf) - 1);
  target = open(dest_buf, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
  if (target < 0) {
    printf("ERROR: Failed to open %s%s\n", "./backups/", argv[1]);
    exit(EXIT_FAILURE);
  }
  while ((ch = fgetc(source)) != EOF)
    write(target, &ch, 1);
  log_wrapper(logf, "Finished back up ", argv[1]);
  fclose(source);
  close(target);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movl   $0xffffffff,-0x94(%rbp)
ff ff ff
cmpl   $0x2,-0x8(%rbp)
je     120e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdff(%rip),%rdi
lea    0xe07(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jne    1259 <main+0x99>
lea    0xde8(%rip),%rdi
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd0(%rip),%rsi
call   10e0 <log_wrapper@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdcf(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    12c1 <main+0x101>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x80(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    $0x64,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1080 <strncat@plt>
lea    -0x80(%rbp),%rdi
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
mov    0x2ca3(%rip),%rax
or     (%rax),%esi
mov    0x2c72(%rip),%rax
or     (%rax),%esi
mov    0x2c81(%rip),%rax
mov    (%rax),%edx
mov    0x2c98(%rip),%rax
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jge    1385 <main+0x1c5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcf6(%rip),%rdi
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    138a <main+0x1ca>
mov    -0x88(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2c3d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     13c7 <main+0x207>
mov    -0x94(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    138a <main+0x1ca>
mov    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc9e(%rip),%rsi
call   10e0 <log_wrapper@plt>
mov    -0x88(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x94(%rbp),%edi
call   10a0 <close@plt>
mov    0x2bb0(%rip),%rax
mov    (%rax),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
je     11e7 <main+0x27>
mov    (%r15),%rsi
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe26(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     132b <main+0x16b>
mov    %rax,%r14
mov    0x8(%r15),%rdx
lea    0xe2e(%rip),%rsi
mov    %rax,%rdi
call   10e0 <log_wrapper@plt>
mov    0x8(%r15),%rdi
lea    0xe2e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     133b <main+0x17b>
mov    %rax,%r12
lea    0xe18(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    0x8(%r15),%rbx
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    $0x63,%edx
sub    %eax,%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strncat@plt>
mov    0x2d8a(%rip),%rax
mov    0x2d53(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d20(%rip),%rax
or     (%rax),%esi
mov    0x2d2f(%rip),%rax
mov    0x2d48(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbp,%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     134f <main+0x18f>
mov    %eax,%ebp
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %al,0xf(%rsp)
mov    0x2d27(%rip),%r13
cmp    0x0(%r13),%al
je     12f1 <main+0x131>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %al,0xf(%rsp)
cmp    0x0(%r13),%al
jne    12d0 <main+0x110>
mov    0x8(%r15),%rdx
lea    0xd7f(%rip),%rsi
mov    %r14,%rdi
call   10e0 <log_wrapper@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf3(%rip),%rdi
lea    0xcdb(%rip),%rsi
jmp    1346 <main+0x186>
mov    0x8(%r15),%rsi
lea    0xcdf(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1368 <main+0x1a8>
mov    0x8(%r15),%rdx
lea    0xd05(%rip),%rdi
lea    0xcf3(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@EOF = global i8 0
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [15 x i8] c"./backups/.log\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"ERROR: Failed to open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [19 x i8] c"Starting back up: \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [11 x i8] c"./backups/\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.7 = [28 x i8] c"ERROR: Failed to open %s%s\0A\00"
@.str.8 = [18 x i8] c"Finished back up \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 [100 x i8]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8, i8* @EOF
store i8 %11, i8* %6
store i32 -1, i32* %10
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14, %2
%20 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i32*, i32** %9
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @log_wrapper(i32* %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %36, i32** %8
%37 = load i32*, i32** %8
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %46
39: ; preds = %27
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %27
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%48 = call i32 @strcpy(i8* %47, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
%55 = sub nsw i32 100, %54
%56 = sub nsw i32 %55, 1
%57 = call i32 @strncat(i8* %49, i8* %52, i32 %56)
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%59 = load i32, i32* @O_CREAT
%60 = load i32, i32* @O_EXCL
%61 = or i32 %59, %60
%62 = load i32, i32* @O_WRONLY
%63 = or i32 %61, %62
%64 = load i32, i32* @S_IRUSR
%65 = load i32, i32* @S_IWUSR
%66 = or i32 %64, %65
%67 = call i32 @open(i8* %58, i32 %63, i32 %66)
store i32 %67, i32* %10
%68 = load i32, i32* %10
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %46
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %73)
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %46
br label %78
78: ; preds = %85, %77
%79 = load i32*, i32** %8
%80 = call signext i8 @fgetc(i32* %79)
store i8 %80, i8* %6
%81 = sext i8 %80 to i32
%82 = load i8, i8* @EOF
%83 = sext i8 %82 to i32
%84 = icmp ne i32 %81, %83
br i1 %84, label %85, label %88
85: ; preds = %78
%86 = load i32, i32* %10
%87 = call i32 @write(i32 %86, i8* %6, i32 1)
br label %78
88: ; preds = %78
%89 = load i32*, i32** %9
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 1
%92 = load i8*, i8** %91
%93 = call i32 @log_wrapper(i32* %89, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %92)
%94 = load i32*, i32** %8
%95 = call i32 @fclose(i32* %94)
%96 = load i32, i32* %10
%97 = call i32 @close(i32 %96)
%98 = load i32, i32* @EXIT_SUCCESS
ret i32 %98
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [15 x i8] c"./backups/.log\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"ERROR: Failed to open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [19 x i8] c"Starting back up: \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [11 x i8] c"./backups/\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.7 = [28 x i8] c"ERROR: Failed to open %s%s\0A\00"
@.str.8 = [18 x i8] c"Finished back up \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7, %2
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %10
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @log_wrapper(i32* %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %18
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i8*, i8** %18
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%31 = load i8*, i8** %18
%32 = call i32 @strlen(i8* %5)
%33 = sub i32 99, %32
%34 = call i32 @strncat(i8* %5, i8* %31, i32 %33)
%35 = load i32, i32* @O_CREAT
%36 = load i32, i32* @O_EXCL
%37 = or i32 %36, %35
%38 = load i32, i32* @O_WRONLY
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IRUSR
%41 = load i32, i32* @S_IWUSR
%42 = or i32 %41, %40
%43 = call i32 @open(i8* %5, i32 %39, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %29
%46 = call signext i8 @fgetc(i32* %22)
store i8 %46, i8* %3
%47 = load i8, i8* @EOF
%48 = icmp eq i8 %46, %47
br i1 %48, label %59, label %54
49: ; preds = %29
%50 = load i8*, i8** %18
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %45, %54
%55 = call i32 @write(i32 %43, i8* %3, i32 1)
%56 = call signext i8 @fgetc(i32* %22)
store i8 %56, i8* %3
%57 = load i8, i8* @EOF
%58 = icmp eq i8 %56, %57
br i1 %58, label %59, label %54
59: ; preds = %54, %45
%60 = load i8*, i8** %18
%61 = call i32 @log_wrapper(i32* %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %60)
%62 = call i32 @fclose(i32* %22)
%63 = call i32 @close(i32 %43)
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}