#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 dbt {
  int dummy;
};
struct dbh {
  int dummy;
};
struct dbf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dbfgetfn(struct dbf *);
int /*<<< orphan*/ dbhadd(struct dbh *, struct dbt *, struct dbf *);
struct dbh *dbhget(unsigned char *);
struct dbh *dbhnew(unsigned char *, int /*<<< orphan*/);
scalar_t__ ext2read(struct dbf *, struct dbt *);
int /*<<< orphan*/ shaget(int /*<<< orphan*/, unsigned char *);
char cifilesha(struct dbt *dt, struct dbf *df) {
  unsigned char sha[20];
  struct dbh *dh;
  char ret = 0;
  if (ext2read(df, dt))
    return 0;
  shaget(dbfgetfn(df), sha);
  if (!(dh = dbhget(sha))) {
    ret = 1;
    dh = dbhnew(sha, 0);
  }
  dbhadd(dh, dt, df);
  return ret;
}


x86 assembly (clang, -O0):
<cifilesha>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x39(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <ext2read@plt>
cmp    $0x0,%rax
je     1194 <cifilesha+0x34>
movb   $0x0,-0x1(%rbp)
jmp    11e9 <cifilesha+0x89>
mov    -0x18(%rbp),%rdi
call   1060 <dbfgetfn@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
call   1030 <shaget@plt>
lea    -0x30(%rbp),%rdi
call   1080 <dbhget@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11d2 <cifilesha+0x72>
movb   $0x1,-0x39(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1040 <dbhnew@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <dbhadd@plt>
mov    -0x39(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cifilesha>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1050 <ext2read@plt>
test   %rax,%rax
je     1182 <cifilesha+0x22>
xor    %ebp,%ebp
jmp    11c3 <cifilesha+0x63>
mov    %rbx,%rdi
call   1060 <dbfgetfn@plt>
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
call   1030 <shaget@plt>
mov    %rbp,%rdi
call   1080 <dbhget@plt>
test   %rax,%rax
je     11a8 <cifilesha+0x48>
xor    %ebp,%ebp
jmp    11b5 <cifilesha+0x55>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <dbhnew@plt>
mov    $0x1,%bpl
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <dbhadd@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dbt = type { i32 }
%struct.dbf = type { i32 }
%struct.dbh = type { i32 }
define signext i8 @cifilesha(%struct.dbt* %0, %struct.dbf* %1) {
%3 = alloca i8
%4 = alloca %struct.dbt*
%5 = alloca %struct.dbf*
%6 = alloca [20 x i8]
%7 = alloca %struct.dbh*
%8 = alloca i8
store %struct.dbt* %0, %struct.dbt** %4
store %struct.dbf* %1, %struct.dbf** %5
store i8 0, i8* %8
%9 = load %struct.dbf*, %struct.dbf** %5
%10 = load %struct.dbt*, %struct.dbt** %4
%11 = call i64 @ext2read(%struct.dbf* %9, %struct.dbt* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i8 0, i8* %3
br label %31
14: ; preds = %2
%15 = load %struct.dbf*, %struct.dbf** %5
%16 = call i32 @dbfgetfn(%struct.dbf* %15)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%18 = call i32 @shaget(i32 %16, i8* %17)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%20 = call %struct.dbh* @dbhget(i8* %19)
store %struct.dbh* %20, %struct.dbh** %7
%21 = icmp ne %struct.dbh* %20, null
br i1 %21, label %25, label %22
22: ; preds = %14
store i8 1, i8* %8
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%24 = call %struct.dbh* @dbhnew(i8* %23, i32 0)
store %struct.dbh* %24, %struct.dbh** %7
br label %25
25: ; preds = %22, %14
%26 = load %struct.dbh*, %struct.dbh** %7
%27 = load %struct.dbt*, %struct.dbt** %4
%28 = load %struct.dbf*, %struct.dbf** %5
%29 = call i32 @dbhadd(%struct.dbh* %26, %struct.dbt* %27, %struct.dbf* %28)
%30 = load i8, i8* %8
store i8 %30, i8* %3
br label %31
31: ; preds = %25, %13
%32 = load i8, i8* %3
ret i8 %32
}

LLVM IR (-O2):
%struct.dbt = type { i32 }
%struct.dbf = type { i32 }
%struct.dbh = type { i32 }
define signext i8 @cifilesha(%struct.dbt* %0, %struct.dbf* %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @ext2read(%struct.dbf* %1, %struct.dbt* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = tail call i32 @dbfgetfn(%struct.dbf* %1)
%9 = call i32 @shaget(i32 %8, i8* %4)
%10 = call %struct.dbh* @dbhget(i8* %4)
%11 = icmp eq %struct.dbh* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call %struct.dbh* @dbhnew(i8* %4, i32 0)
br label %14
14: ; preds = %12, %7
%15 = phi %struct.dbh* [ %10, %7 ], [ %13, %12 ]
%16 = phi i8 [ 0, %7 ], [ 1, %12 ]
%17 = call i32 @dbhadd(%struct.dbh* %15, %struct.dbt* %0, %struct.dbf* %1)
br label %18
18: ; preds = %2, %14
%19 = phi i8 [ %16, %14 ], [ 0, %2 ]
ret i8 %19
}