#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*/ result;
typedef scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ cal_sha1(char *, int, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int main(void) {
  char result[41];
  int32_t ret = -1;
  ret = cal_sha1(result, sizeof(result),
                 "abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123", 1);
  if (ret == 0 &&
      0 == strncmp(result, "5e8ea80e5c1f2debab393d2678b0279ae2089bc4",
                   strlen(result))) {
    printf("test 1 successful!\n");
  } else {
    printf("test 1 failed!\n");
  }
  ret = cal_sha1(result, sizeof(result),
                 "abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234", 0);
  if (ret == 0 &&
      0 == strncmp(result, "70ED417BFA26AFF9BE6F6D7841197F29FE16A994",
                   strlen(result))) {
    printf("test 2 successful!\n");
  } else {
    printf("test 2 failed!\n");
  }
  ret =
      cal_sha1(result, sizeof(result),
               "abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345", 0);
  if (ret == 0 &&
      0 == strncmp(result, "413CB77D8DF41D00739F51D93A2507EFE1900C80",
                   strlen(result))) {
    printf("test 3 successful!\n");
  } else {
    printf("test 3 failed!\n");
  }
  ret = cal_sha1(result, sizeof(result), "", 1);
  if (ret == 0 &&
      0 == strncmp(result, "da39a3ee5e6b4b0d3255bfef95601890afd80709",
                   strlen(result))) {
    printf("test 4 successful!\n");
  } else {
    printf("test 4 failed!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xffffffffffffffff,-0x38(%rbp)
ff
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xe99(%rip),%rdx
mov    $0x1,%ecx
call   1040 <cal_sha1@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c2 <main+0x82>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xe9a(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c2 <main+0x82>
lea    0xea9(%rip),%rdi
call   1060 <printf@plt>
jmp    11ce <main+0x8e>
lea    0xeac(%rip),%rdi
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xea7(%rip),%rdx
xor    %ecx,%ecx
call   1040 <cal_sha1@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1236 <main+0xf6>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xeac(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1236 <main+0xf6>
lea    0xebb(%rip),%rdi
call   1060 <printf@plt>
jmp    1242 <main+0x102>
lea    0xebe(%rip),%rdi
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xeb9(%rip),%rdx
xor    %ecx,%ecx
call   1040 <cal_sha1@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12aa <main+0x16a>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    0xebf(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12aa <main+0x16a>
lea    0xece(%rip),%rdi
call   1060 <printf@plt>
jmp    12b6 <main+0x176>
lea    0xed1(%rip),%rdi
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xdbe(%rip),%rdx
mov    $0x1,%ecx
call   1040 <cal_sha1@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1321 <main+0x1e1>
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xe95(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1321 <main+0x1e1>
lea    0xea4(%rip),%rdi
call   1060 <printf@plt>
jmp    132d <main+0x1ed>
lea    0xea7(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xeb4(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
mov    $0x1,%ecx
call   1050 <cal_sha1@plt>
test   %rax,%rax
jne    1188 <main+0x48>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     127b <main+0x13b>
lea    0xfc0(%rip),%rdi
call   1040 <puts@plt>
lea    0xec6(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
xor    %ecx,%ecx
call   1050 <cal_sha1@plt>
test   %rax,%rax
jne    11d4 <main+0x94>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xed9(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1287 <main+0x147>
lea    0xf83(%rip),%rdi
call   1040 <puts@plt>
lea    0xedc(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
xor    %ecx,%ecx
call   1050 <cal_sha1@plt>
test   %rax,%rax
jne    121c <main+0xdc>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xef0(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1293 <main+0x153>
lea    0xf4a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf2e(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
mov    $0x1,%ecx
call   1050 <cal_sha1@plt>
test   %rax,%rax
jne    1267 <main+0x127>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     129c <main+0x15c>
lea    0xf0e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xf42(%rip),%rdi
jmp    118f <main+0x4f>
lea    0xf23(%rip),%rdi
jmp    11db <main+0x9b>
lea    0xf04(%rip),%rdi
jmp    1223 <main+0xe3>
lea    0xee8(%rip),%rdi
jmp    126e <main+0x12e>

LLVM IR (-O0):
@.str = [56 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123\00"
@.str.1 = [41 x i8] c"5e8ea80e5c1f2debab393d2678b0279ae2089bc4\00"
@.str.2 = [20 x i8] c"test 1 successful!\0A\00"
@.str.3 = [16 x i8] c"test 1 failed!\0A\00"
@.str.4 = [57 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234\00"
@.str.5 = [41 x i8] c"70ED417BFA26AFF9BE6F6D7841197F29FE16A994\00"
@.str.6 = [20 x i8] c"test 2 successful!\0A\00"
@.str.7 = [16 x i8] c"test 2 failed!\0A\00"
@.str.8 = [58 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345\00"
@.str.9 = [41 x i8] c"413CB77D8DF41D00739F51D93A2507EFE1900C80\00"
@.str.10 = [20 x i8] c"test 3 successful!\0A\00"
@.str.11 = [16 x i8] c"test 3 failed!\0A\00"
@.str.12 = [1 x i8] zeroinitializer
@.str.13 = [41 x i8] c"da39a3ee5e6b4b0d3255bfef95601890afd80709\00"
@.str.14 = [20 x i8] c"test 4 successful!\0A\00"
@.str.15 = [16 x i8] c"test 4 failed!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [41 x i8]
%3 = alloca i64
store i32 0, i32* %1
store i64 -1, i64* %3
%4 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%5 = call i64 @cal_sha1(i8* %4, i32 41, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 1)
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 0, %12
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %8, %0
%17 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%20 = call i64 @cal_sha1(i8* %19, i32 41, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 0)
store i64 %20, i64* %3
%21 = load i64, i64* %3
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 0, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %33
31: ; preds = %23, %18
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%35 = call i64 @cal_sha1(i8* %34, i32 41, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0), i32 0)
store i64 %35, i64* %3
%36 = load i64, i64* %3
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i32 %41)
%43 = icmp eq i64 0, %42
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %48
46: ; preds = %38, %33
%47 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %48
48: ; preds = %46, %44
%49 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%50 = call i64 @cal_sha1(i8* %49, i32 41, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.12, i64 0, i64 0), i32 1)
store i64 %50, i64* %3
%51 = load i64, i64* %3
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %48
%54 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%55 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i64 @strncmp(i8* %54, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.13, i64 0, i64 0), i32 %56)
%58 = icmp eq i64 0, %57
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0))
br label %63
61: ; preds = %53, %48
%62 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.15, i64 0, i64 0))
br label %63
63: ; preds = %61, %59
ret i32 0
}

LLVM IR (-O2):
@.str = [56 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123\00"
@.str.1 = [41 x i8] c"5e8ea80e5c1f2debab393d2678b0279ae2089bc4\00"
@.str.4 = [57 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234\00"
@.str.5 = [41 x i8] c"70ED417BFA26AFF9BE6F6D7841197F29FE16A994\00"
@.str.8 = [58 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345\00"
@.str.9 = [41 x i8] c"413CB77D8DF41D00739F51D93A2507EFE1900C80\00"
@.str.12 = [1 x i8] zeroinitializer
@.str.13 = [41 x i8] c"da39a3ee5e6b4b0d3255bfef95601890afd80709\00"
@str = [15 x i8] c"test 1 failed!\00"
@str.16 = [15 x i8] c"test 2 failed!\00"
@str.17 = [15 x i8] c"test 3 failed!\00"
@str.18 = [15 x i8] c"test 4 failed!\00"
@str.19 = [19 x i8] c"test 4 successful!\00"
@str.20 = [19 x i8] c"test 3 successful!\00"
@str.21 = [19 x i8] c"test 2 successful!\00"
@str.22 = [19 x i8] c"test 1 successful!\00"
define i32 @main() {
%1 = alloca [41 x i8]
%2 = getelementptr inbounds [41 x i8], [41 x i8]* %1, i64 0, i64 0
%3 = call i64 @cal_sha1(i8* %2, i32 41, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @strlen(i8* %2)
%7 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %5, %0
br label %10
10: ; preds = %5, %9
%11 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.22, i64 0, i64 0), %5 ]
%12 = call i32 @puts(i8* dereferenceable(1) %11)
%13 = call i64 @cal_sha1(i8* %2, i32 41, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = call i32 @strlen(i8* %2)
%17 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15, %10
br label %20
20: ; preds = %15, %19
%21 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.16, i64 0, i64 0), %19 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.21, i64 0, i64 0), %15 ]
%22 = call i32 @puts(i8* dereferenceable(1) %21)
%23 = call i64 @cal_sha1(i8* %2, i32 41, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0), i32 0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = call i32 @strlen(i8* %2)
%27 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25, %20
br label %30
30: ; preds = %25, %29
%31 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.17, i64 0, i64 0), %29 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.20, i64 0, i64 0), %25 ]
%32 = call i32 @puts(i8* dereferenceable(1) %31)
%33 = call i64 @cal_sha1(i8* %2, i32 41, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.12, i64 0, i64 0), i32 1)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = call i32 @strlen(i8* %2)
%37 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.13, i64 0, i64 0), i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %35, %30
br label %40
40: ; preds = %35, %39
%41 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.18, i64 0, i64 0), %39 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.19, i64 0, i64 0), %35 ]
%42 = call i32 @puts(i8* dereferenceable(1) %41)
ret i32 0
}