#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_md5(char *, int, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int32_t main(void) {
  char result[41];
  int32_t ret = -1;
  ret = cal_md5(result, sizeof(result),
                "abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123", 1);
  if (ret == 0 && 0 == strncmp(result, "dd2fc541b65e2202d55beae0ecaf6528",
                               strlen(result))) {
    printf("test 1 successful!\n");
  } else {
    printf("test 1 failed!\n");
  }
  ret = cal_md5(result, sizeof(result),
                "abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234", 0);
  if (ret == 0 && 0 == strncmp(result, "27FF2E8344E7E3F36F9C7E18D0EC82DF",
                               strlen(result))) {
    printf("test 2 successful!\n");
  } else {
    printf("test 2 failed!\n");
  }
  ret = cal_md5(result, sizeof(result),
                "abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345", 0);
  if (ret == 0 && 0 == strncmp(result, "7A7B1279343946E3A5949BEA1B3BF8AF",
                               strlen(result))) {
    printf("test 3 successful!\n");
  } else {
    printf("test 3 failed!\n");
  }
  ret = cal_md5(result, sizeof(result), "", 1);
  if (ret == 0 && 0 == strncmp(result, "d41d8cd98f00b204e9800998ecf8427e",
                               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
movq   $0xffffffffffffffff,-0x38(%rbp)
ff
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xea0(%rip),%rdx
mov    $0x1,%ecx
call   1060 <cal_md5@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11bb <main+0x7b>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xea1(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11bb <main+0x7b>
lea    0xea8(%rip),%rdi
call   1050 <printf@plt>
jmp    11c7 <main+0x87>
lea    0xeab(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xea6(%rip),%rdx
xor    %ecx,%ecx
call   1060 <cal_md5@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122f <main+0xef>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xeab(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    122f <main+0xef>
lea    0xeb2(%rip),%rdi
call   1050 <printf@plt>
jmp    123b <main+0xfb>
lea    0xeb5(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xeb0(%rip),%rdx
xor    %ecx,%ecx
call   1060 <cal_md5@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12a3 <main+0x163>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    0xeb6(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12a3 <main+0x163>
lea    0xebd(%rip),%rdi
call   1050 <printf@plt>
jmp    12af <main+0x16f>
lea    0xec0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x29,%esi
lea    0xdbd(%rip),%rdx
mov    $0x1,%ecx
call   1060 <cal_md5@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    131a <main+0x1da>
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xe84(%rip),%rsi
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    131a <main+0x1da>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
jmp    1326 <main+0x1e6>
lea    0xe8e(%rip),%rdi
call   1050 <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   1060 <cal_md5@plt>
test   %rax,%rax
jne    1188 <main+0x48>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     127b <main+0x13b>
lea    0xfa0(%rip),%rdi
call   1040 <puts@plt>
lea    0xebe(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
xor    %ecx,%ecx
call   1060 <cal_md5@plt>
test   %rax,%rax
jne    11d4 <main+0x94>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xed1(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1287 <main+0x147>
lea    0xf63(%rip),%rdi
call   1040 <puts@plt>
lea    0xecc(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
xor    %ecx,%ecx
call   1060 <cal_md5@plt>
test   %rax,%rax
jne    121c <main+0xdc>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xee0(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1293 <main+0x153>
lea    0xf2a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf0e(%rip),%rdx
mov    %rsp,%rdi
mov    $0x29,%esi
mov    $0x1,%ecx
call   1060 <cal_md5@plt>
test   %rax,%rax
jne    1267 <main+0x127>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     129c <main+0x15c>
lea    0xeee(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xf22(%rip),%rdi
jmp    118f <main+0x4f>
lea    0xf03(%rip),%rdi
jmp    11db <main+0x9b>
lea    0xee4(%rip),%rdi
jmp    1223 <main+0xe3>
lea    0xec8(%rip),%rdi
jmp    126e <main+0x12e>

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

LLVM IR (-O2):
@.str = [56 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz123\00"
@.str.1 = [33 x i8] c"dd2fc541b65e2202d55beae0ecaf6528\00"
@.str.4 = [57 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234\00"
@.str.5 = [33 x i8] c"27FF2E8344E7E3F36F9C7E18D0EC82DF\00"
@.str.8 = [58 x i8] c"abcdegfhijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345\00"
@.str.9 = [33 x i8] c"7A7B1279343946E3A5949BEA1B3BF8AF\00"
@.str.12 = [1 x i8] zeroinitializer
@.str.13 = [33 x i8] c"d41d8cd98f00b204e9800998ecf8427e\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 i64 @main() {
%1 = alloca [41 x i8]
%2 = getelementptr inbounds [41 x i8], [41 x i8]* %1, i64 0, i64 0
%3 = call i64 @cal_md5(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 ([33 x i8], [33 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_md5(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 ([33 x i8], [33 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_md5(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 ([33 x i8], [33 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_md5(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 ([33 x i8], [33 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 i64 0
}