#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 st_nlink;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ ReadName(int, char *);
scalar_t__ ReadStat(int, struct stat *);
int /*<<< orphan*/ RecoverDir(char *, struct stat *);
int /*<<< orphan*/ RecoverFile(int, char *, struct stat *);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void RecoverBackup(int bfd) {
  char name[2048];
  while (ReadName(bfd, name) > 0) {
    struct stat backupnode;
    if (ReadStat(bfd, &backupnode) == 0) {
      fprintf(stderr, "error reading backup stat\n");
      exit(1);
    }
    if (S_ISREG(backupnode.st_mode)) {
      if (backupnode.st_nlink > 1) {
        fprintf(stderr,
                "link-counter: %i. hardlinks will not be restored and create "
                "new files.\n",
                (int)backupnode.st_nlink);
      }
      RecoverFile(bfd, name, &backupnode);
    } else if (S_ISDIR(backupnode.st_mode)) {
      RecoverDir(name, &backupnode);
    } else {
      fprintf(stderr, "this type is currently not supported.\n");
    }
  }
}


x86 assembly (clang, -O0):
<RecoverBackup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1050 <ReadName@plt>
cmp    $0x0,%rax
jle    1289 <RecoverBackup+0x109>
mov    -0x4(%rbp),%edi
lea    -0x818(%rbp),%rsi
call   1030 <ReadStat@plt>
cmp    $0x0,%rax
jne    11e1 <RecoverBackup+0x61>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x814(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%rax
je     123b <RecoverBackup+0xbb>
cmpl   $0x1,-0x818(%rbp)
jle    1220 <RecoverBackup+0xa0>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x818(%rbp),%edx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
lea    -0x818(%rbp),%rdx
call   10a0 <RecoverFile@plt>
jmp    1284 <RecoverBackup+0x104>
mov    -0x814(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1268 <RecoverBackup+0xe8>
lea    -0x810(%rbp),%rdi
lea    -0x818(%rbp),%rsi
call   1080 <RecoverDir@plt>
jmp    127f <RecoverBackup+0xff>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1284 <RecoverBackup+0x104>
jmp    118e <RecoverBackup+0xe>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RecoverBackup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%rsi
call   1050 <ReadName@plt>
test   %rax,%rax
jle    125a <RecoverBackup+0xda>
lea    0x8(%rsp),%r14
mov    0x2e2e(%rip),%rbp
lea    0xeaa(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xe56(%rip),%r13
jmp    11ec <RecoverBackup+0x6c>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   10a0 <RecoverFile@plt>
mov    %ebx,%edi
mov    %r12,%rsi
call   1050 <ReadName@plt>
test   %rax,%rax
jle    125a <RecoverBackup+0xda>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <ReadStat@plt>
test   %rax,%rax
je     126c <RecoverBackup+0xec>
mov    0xc(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %rax,%rax
je     1230 <RecoverBackup+0xb0>
mov    0x8(%rsp),%edx
cmp    $0x2,%edx
jl     11d0 <RecoverBackup+0x50>
mov    0x0(%rbp),%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d0 <RecoverBackup+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     124b <RecoverBackup+0xcb>
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <RecoverDir@plt>
jmp    11dd <RecoverBackup+0x5d>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11dd <RecoverBackup+0x5d>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%edi
lea    0xd8a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [27 x i8] c"error reading backup stat\0A\00"
@.str.1 = [72 x i8] c"link-counter: %i. hardlinks will not be restored and create new files.\0A\00"
@.str.2 = [39 x i8] c"this type is currently not supported.\0A\00"
define void @RecoverBackup(i32 %0) {
%2 = alloca i32
%3 = alloca [2048 x i8]
%4 = alloca %struct.stat
store i32 %0, i32* %2
br label %5
5: ; preds = %48, %1
%6 = load i32, i32* %2
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%8 = call i64 @ReadName(i32 %6, i8* %7)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %49
10: ; preds = %5
%11 = load i32, i32* %2
%12 = call i64 @ReadStat(i32 %11, %struct.stat* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i64 @S_ISREG(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%25 = load i32, i32* %24
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %27, %23
%33 = load i32, i32* %2
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%35 = call i32 @RecoverFile(i32 %33, i8* %34, %struct.stat* %4)
br label %48
36: ; preds = %18
%37 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i64 @S_ISDIR(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%43 = call i32 @RecoverDir(i8* %42, %struct.stat* %4)
br label %47
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %44, %41
br label %48
48: ; preds = %47, %32
br label %5
49: ; preds = %5
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [27 x i8] c"error reading backup stat\0A\00"
@.str.1 = [72 x i8] c"link-counter: %i. hardlinks will not be restored and create new files.\0A\00"
@.str.2 = [39 x i8] c"this type is currently not supported.\0A\00"
define void @RecoverBackup(i32 %0) {
%2 = alloca [2048 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = call i64 @ReadName(i32 %0, i8* %4)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %42
7: ; preds = %1
%8 = bitcast %struct.stat* %3 to i8*
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %11
11: ; preds = %7, %39
%12 = call i64 @ReadStat(i32 %0, %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i32, i32* %9
%20 = call i64 @S_ISREG(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %18
%23 = load i32, i32* %10
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %28
28: ; preds = %25, %22
%29 = call i32 @RecoverFile(i32 %0, i8* %4, %struct.stat* %3)
br label %39
30: ; preds = %18
%31 = load i32, i32* %9
%32 = call i64 @S_ISDIR(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @RecoverDir(i8* %4, %struct.stat* %3)
br label %39
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %34, %36, %28
%40 = call i64 @ReadName(i32 %0, i8* %4)
%41 = icmp sgt i64 %40, 0
br i1 %41, label %11, label %42
42: ; preds = %39, %1
ret void
}