#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 */

/* Variables and functions */
int diff_tree(void *, unsigned long, void *, unsigned long, char const *);
int /*<<< orphan*/ free(void *);
void *read_sha1_file(unsigned char const *, char *, unsigned long *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
                   const char *base) {
  void *tree1, *tree2;
  unsigned long size1, size2;
  char type[20];
  int retval;
  tree1 = read_sha1_file(old, type, &size1);
  if (!tree1 || strcmp(type, "tree"))
    usage("unable to read source tree");
  tree2 = read_sha1_file(new, type, &size2);
  if (!tree2 || strcmp(type, "tree"))
    usage("unable to read destination tree");
  retval = diff_tree(tree1, size1, tree2, size2, base);
  free(tree1);
  free(tree2);
  return retval;
}


x86 assembly (clang, -O0):
<diff_tree_sha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <read_sha1_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119e <diff_tree_sha1+0x4e>
lea    -0x50(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11aa <diff_tree_sha1+0x5a>
lea    0xe5b(%rip),%rdi
call   1070 <usage@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1060 <read_sha1_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e4 <diff_tree_sha1+0x94>
lea    -0x50(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f0 <diff_tree_sha1+0xa0>
lea    0xe30(%rip),%rdi
call   1070 <usage@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <diff_tree@plt>
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diff_tree_sha1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1060 <read_sha1_file@plt>
mov    %rax,%r15
test   %rax,%rax
je     118d <diff_tree_sha1+0x3d>
lea    0xe98(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1199 <diff_tree_sha1+0x49>
lea    0xe6c(%rip),%rdi
call   1070 <usage@plt>
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1060 <read_sha1_file@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c7 <diff_tree_sha1+0x77>
lea    0xe5e(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d3 <diff_tree_sha1+0x83>
lea    0xe4d(%rip),%rdi
call   1070 <usage@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rcx
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%r8
call   1040 <diff_tree@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"tree\00"
@.str.1 = [27 x i8] c"unable to read source tree\00"
@.str.2 = [32 x i8] c"unable to read destination tree\00"
define i32 @diff_tree_sha1(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca [20 x i8]
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%15 = call i8* @read_sha1_file(i8* %13, i8* %14, i64* %9)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18, %3
%23 = call i32 @usage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i8*, i8** %5
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%27 = call i8* @read_sha1_file(i8* %25, i8* %26, i64* %10)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30, %24
%35 = call i32 @usage(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = load i8*, i8** %7
%38 = load i64, i64* %9
%39 = load i8*, i8** %8
%40 = load i64, i64* %10
%41 = load i8*, i8** %6
%42 = call i32 @diff_tree(i8* %37, i64 %38, i8* %39, i64 %40, i8* %41)
store i32 %42, i32* %12
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %8
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %12
ret i32 %47
}

LLVM IR (-O2):
@.str = [5 x i8] c"tree\00"
@.str.1 = [27 x i8] c"unable to read source tree\00"
@.str.2 = [32 x i8] c"unable to read destination tree\00"
define i32 @diff_tree_sha1(i8* %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca [20 x i8]
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%10 = call i8* @read_sha1_file(i8* %0, i8* %9, i64* %4)
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12, %3
%16 = call i32 @usage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = call i8* @read_sha1_file(i8* %1, i8* %9, i64* %5)
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20, %17
%24 = call i32 @usage(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i64, i64* %4
%27 = load i64, i64* %5
%28 = call i32 @diff_tree(i8* %10, i64 %26, i8* %18, i64 %27, i8* %2)
%29 = call i32 @free(i8* %10)
%30 = call i32 @free(i8* %18)
ret i32 %28
}