#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 /*<<< orphan*/ ap_snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ shaBlock(unsigned char *, scalar_t__, unsigned char *);
scalar_t__ strlen(char const *);
void shahash_r(const char *str, char hashbuf[41]) {
  int x;
  char *pos;
  unsigned char hashval[20];
  if (!str || strlen(str) == 0)
    return;
  shaBlock((unsigned char *)str, strlen(str), hashval);
  pos = hashbuf;
  for (x = 0; x < 20; x++) {
    ap_snprintf(pos, 3, "%02x", hashval[x]);
    pos += 2;
  }
  return;
}


x86 assembly (clang, -O0):
<shahash_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115e <shahash_r+0x2e>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1163 <shahash_r+0x33>
jmp    11da <shahash_r+0xaa>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
lea    -0x40(%rbp),%rdx
call   1040 <shaBlock@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    11d5 <shahash_r+0xa5>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    $0x3,%esi
lea    0xe4f(%rip),%rdx
movzbl -0x40(%rbp,%rax,1),%ecx
call   1050 <ap_snprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <shahash_r+0x63>
jmp    11da <shahash_r+0xaa>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shahash_r>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %rdi,%rdi
je     1324 <shahash_r+0x1f4>
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     1324 <shahash_r+0x1f4>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <shaBlock@plt>
movzbl (%rsp),%ecx
lea    0xe91(%rip),%r14
mov    %r15,%rdi
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x2(%r15),%rdi
movzbl 0x1(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x4(%r15),%rdi
movzbl 0x2(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x6(%r15),%rdi
movzbl 0x3(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x8(%r15),%rdi
movzbl 0x4(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0xa(%r15),%rdi
movzbl 0x5(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0xc(%r15),%rdi
movzbl 0x6(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0xe(%r15),%rdi
movzbl 0x7(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x10(%r15),%rdi
movzbl 0x8(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x12(%r15),%rdi
movzbl 0x9(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x14(%r15),%rdi
movzbl 0xa(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x16(%r15),%rdi
movzbl 0xb(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x18(%r15),%rdi
movzbl 0xc(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x1a(%r15),%rdi
movzbl 0xd(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x1c(%r15),%rdi
movzbl 0xe(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x1e(%r15),%rdi
movzbl 0xf(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x20(%r15),%rdi
movzbl 0x10(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x22(%r15),%rdi
movzbl 0x11(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
lea    0x24(%r15),%rdi
movzbl 0x12(%rsp),%ecx
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
add    $0x26,%r15
movzbl 0x13(%rsp),%ecx
mov    %r15,%rdi
mov    $0x3,%esi
mov    %r14,%rdx
call   1050 <ap_snprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define void @shahash_r(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [20 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10, %2
br label %38
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%20 = call i32 @shaBlock(i8* %16, i64 %18, i8* %19)
%21 = load i8*, i8** %4
store i8* %21, i8** %6
store i32 0, i32* %5
br label %22
22: ; preds = %34, %15
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 20
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i8*, i8** %6
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @ap_snprintf(i8* %26, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %30)
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %6
br label %34
34: ; preds = %25
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %22
37: ; preds = %22
br label %38
38: ; preds = %37, %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @shahash_r(i8* %0, i8* %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %89, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %89, label %9
9: ; preds = %6
%10 = call i32 @shaBlock(i8* %0, i64 %7, i8* %4)
%11 = load i8, i8* %4
%12 = call i32 @ap_snprintf(i8* %1, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
%13 = getelementptr inbounds i8, i8* %1, i64 2
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 1
%15 = load i8, i8* %14
%16 = call i32 @ap_snprintf(i8* %13, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
%17 = getelementptr inbounds i8, i8* %1, i64 4
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 2
%19 = load i8, i8* %18
%20 = call i32 @ap_snprintf(i8* %17, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %19)
%21 = getelementptr inbounds i8, i8* %1, i64 6
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 3
%23 = load i8, i8* %22
%24 = call i32 @ap_snprintf(i8* %21, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %23)
%25 = getelementptr inbounds i8, i8* %1, i64 8
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 4
%27 = load i8, i8* %26
%28 = call i32 @ap_snprintf(i8* %25, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %27)
%29 = getelementptr inbounds i8, i8* %1, i64 10
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 5
%31 = load i8, i8* %30
%32 = call i32 @ap_snprintf(i8* %29, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
%33 = getelementptr inbounds i8, i8* %1, i64 12
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 6
%35 = load i8, i8* %34
%36 = call i32 @ap_snprintf(i8* %33, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %35)
%37 = getelementptr inbounds i8, i8* %1, i64 14
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 7
%39 = load i8, i8* %38
%40 = call i32 @ap_snprintf(i8* %37, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %39)
%41 = getelementptr inbounds i8, i8* %1, i64 16
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 8
%43 = load i8, i8* %42
%44 = call i32 @ap_snprintf(i8* %41, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %43)
%45 = getelementptr inbounds i8, i8* %1, i64 18
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 9
%47 = load i8, i8* %46
%48 = call i32 @ap_snprintf(i8* %45, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %47)
%49 = getelementptr inbounds i8, i8* %1, i64 20
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 10
%51 = load i8, i8* %50
%52 = call i32 @ap_snprintf(i8* %49, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
%53 = getelementptr inbounds i8, i8* %1, i64 22
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 11
%55 = load i8, i8* %54
%56 = call i32 @ap_snprintf(i8* %53, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %55)
%57 = getelementptr inbounds i8, i8* %1, i64 24
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 12
%59 = load i8, i8* %58
%60 = call i32 @ap_snprintf(i8* %57, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %59)
%61 = getelementptr inbounds i8, i8* %1, i64 26
%62 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 13
%63 = load i8, i8* %62
%64 = call i32 @ap_snprintf(i8* %61, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %63)
%65 = getelementptr inbounds i8, i8* %1, i64 28
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 14
%67 = load i8, i8* %66
%68 = call i32 @ap_snprintf(i8* %65, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %67)
%69 = getelementptr inbounds i8, i8* %1, i64 30
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 15
%71 = load i8, i8* %70
%72 = call i32 @ap_snprintf(i8* %69, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %71)
%73 = getelementptr inbounds i8, i8* %1, i64 32
%74 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 16
%75 = load i8, i8* %74
%76 = call i32 @ap_snprintf(i8* %73, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %75)
%77 = getelementptr inbounds i8, i8* %1, i64 34
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 17
%79 = load i8, i8* %78
%80 = call i32 @ap_snprintf(i8* %77, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %79)
%81 = getelementptr inbounds i8, i8* %1, i64 36
%82 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 18
%83 = load i8, i8* %82
%84 = call i32 @ap_snprintf(i8* %81, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %83)
%85 = getelementptr inbounds i8, i8* %1, i64 38
%86 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 19
%87 = load i8, i8* %86
%88 = call i32 @ap_snprintf(i8* %85, i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %87)
br label %89
89: ; preds = %9, %2, %6
ret void
}