#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*/ EVP_sha1();
unsigned char *digest_message(int /*<<< orphan*/, unsigned char *,
                              int /*<<< orphan*/, unsigned int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(unsigned char *);
void sha_128(unsigned char *str) {
  int i;
  unsigned int ol;
  unsigned char *r;
  r = digest_message(EVP_sha1(), str, strlen(str), &ol);
  for (i = 0; i < ol; i++)
    fprintf(stderr, "%02x", r[i]);
  fprintf(stderr, "\n");
  free(r);
}


x86 assembly (clang, -O0):
<sha_128>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <EVP_sha1@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
call   1070 <digest_message@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11d1 <sha_128+0x81>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <sha_128+0x44>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha_128>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <EVP_sha1@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <digest_message@plt>
mov    %rax,%rbx
cmpl   $0x0,0x4(%rsp)
je     11be <sha_128+0x6e>
mov    0x2e53(%rip),%r15
lea    0xe6c(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%edi
movzbl (%rbx,%rbp,1),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbp
mov    0x4(%rsp),%eax
cmp    %rax,%rbp
jb     11a0 <sha_128+0x50>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @sha_128(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i32 (...) @EVP_sha1()
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = call i8* @digest_message(i32 %6, i8* %7, i32 %9, i32* %4)
store i8* %10, i8** %5
store i32 0, i32* %3
br label %11
11: ; preds = %24, %1
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %15
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %11
27: ; preds = %11
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** %5
%31 = call i32 @free(i8* %30)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @sha_128(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @EVP_sha1()
%5 = tail call i32 @strlen(i8* %0)
%6 = call i8* @digest_message(i32 %4, i8* %0, i32 %5, i32* %2)
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %16, %9 ], [ 0, %1 ]
%11 = load i32, i32* @stderr
%12 = getelementptr inbounds i8, i8* %6, i64 %10
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i64 %10, 1
%17 = load i32, i32* %2
%18 = zext i32 %17 to i64
%19 = icmp ult i64 %16, %18
br i1 %19, label %9, label %20
20: ; preds = %9, %1
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @free(i8* %6)
ret void
}