#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ BackupNode(char *, struct stat *, int);
int /*<<< orphan*/ WriteMagicBytes(int);
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *targetname = getenv("BACKUPDEVICE");
  int targetfd;
  struct stat targetinode;
  if (!targetname) {
    fprintf(stderr, "BACKUPDEVICE environment variable not set\n");
    return 1;
  }
  if ((targetfd = creat(targetname, 0660)) == -1) {
    perror("Backuptarget: ");
    return 2;
  }
  if (fstat(targetfd, &targetinode) == -1) {
    perror("Backuptarget: ");
    return 3;
  }
  WriteMagicBytes(targetfd);
  if (argc == 1) {
    BackupNode(".", &targetinode, targetfd);
  } else {
    while (--argc) {
      BackupNode(*++argv, &targetinode, targetfd);
    }
  }
  close(targetfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <main+0x52>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12aa <main+0x12a>
mov    -0x18(%rbp),%rdi
mov    $0x1b0,%esi
call   1090 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1204 <main+0x84>
lea    0xe45(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12aa <main+0x12a>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1231 <main+0xb1>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    12aa <main+0x12a>
mov    -0x1c(%rbp),%edi
call   1040 <WriteMagicBytes@plt>
cmpl   $0x1,-0x8(%rbp)
jne    125b <main+0xdb>
mov    -0x1c(%rbp),%edx
lea    0xdfa(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <BackupNode@plt>
jmp    129b <main+0x11b>
jmp    1260 <main+0xe0>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1296 <main+0x116>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1060 <BackupNode@plt>
jmp    1260 <main+0xe0>
jmp    129b <main+0x11b>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f5 <main+0x75>
mov    %rax,%rdi
mov    $0x1b0,%esi
call   1090 <creat@plt>
cmp    $0xffffffff,%eax
je     124e <main+0xce>
mov    %eax,%r12d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0xe1>
mov    %r12d,%edi
call   1040 <WriteMagicBytes@plt>
cmp    $0x1,%r14d
jne    1211 <main+0x91>
lea    0xe61(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %r12d,%edx
call   1060 <BackupNode@plt>
jmp    1237 <main+0xb7>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    1241 <main+0xc1>
mov    %r14d,%ebx
mov    $0x1,%ebp
lea    0x8(%rsp),%r14
xchg   %ax,%ax
mov    (%r15,%rbp,8),%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1060 <BackupNode@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1220 <main+0xa0>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde3(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
jmp    1241 <main+0xc1>
lea    0xdd0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3,%eax
jmp    1241 <main+0xc1>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [13 x i8] c"BACKUPDEVICE\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"BACKUPDEVICE environment variable not set\0A\00"
@.str.2 = [15 x i8] c"Backuptarget: \00"
@.str.3 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %50
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i32 @creat(i8* %16, i32 432)
store i32 %17, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %50
21: ; preds = %15
%22 = load i32, i32* %7
%23 = call i32 @fstat(i32 %22, %struct.stat* %8)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %3
br label %50
27: ; preds = %21
%28 = load i32, i32* %7
%29 = call i32 @WriteMagicBytes(i32 %28)
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %7
%34 = call i32 @BackupNode(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %8, i32 %33)
br label %47
35: ; preds = %27
br label %36
36: ; preds = %40, %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i32 1
store i8** %42, i8*** %5
%43 = load i8*, i8** %42
%44 = load i32, i32* %7
%45 = call i32 @BackupNode(i8* %43, %struct.stat* %8, i32 %44)
br label %36
46: ; preds = %36
br label %47
47: ; preds = %46, %32
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
store i32 0, i32* %3
br label %50
50: ; preds = %47, %25, %19, %12
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [13 x i8] c"BACKUPDEVICE\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"BACKUPDEVICE environment variable not set\0A\00"
@.str.2 = [15 x i8] c"Backuptarget: \00"
@.str.3 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = bitcast %struct.stat* %3 to i8*
%6 = icmp eq i8* %4, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %37
10: ; preds = %2
%11 = tail call i32 @creat(i8* %4, i32 432)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %37
15: ; preds = %10
%16 = call i32 @fstat(i32 %11, %struct.stat* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %37
20: ; preds = %15
%21 = tail call i32 @WriteMagicBytes(i32 %11)
%22 = icmp eq i32 %0, 1
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = add nsw i32 %0, -1
br label %27
25: ; preds = %20
%26 = call i32 @BackupNode(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %3, i32 %11)
br label %35
27: ; preds = %23, %27
%28 = phi i32 [ %33, %27 ], [ %24, %23 ]
%29 = phi i8** [ %30, %27 ], [ %1, %23 ]
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @BackupNode(i8* %31, %struct.stat* %3, i32 %11)
%33 = add nsw i32 %28, -1
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %27
35: ; preds = %27, %25
%36 = call i32 @close(i32 %11)
br label %37
37: ; preds = %35, %18, %13, %7
%38 = phi i32 [ 2, %13 ], [ 3, %18 ], [ 0, %35 ], [ 1, %7 ]
ret i32 %38
}