#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*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
char *sha1(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  puts("Sha1 hash test");
  if (argc >= 2) {
    printf("Hash of \"%s\"\n", argv[1]);
    puts(sha1(argv[1], strlen(argv[1])));
  } else {
    puts(sha1("", 0));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x2,-0x8(%rbp)
jl     11b1 <main+0x71>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe94(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1040 <sha1@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
jmp    11c7 <main+0x87>
lea    0xe64(%rip),%rdi
xor    %esi,%esi
call   1040 <sha1@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebp
jl     117c <main+0x3c>
mov    0x8(%rbx),%rsi
lea    0xeab(%rip),%rdi
call   1060 <printf@plt>
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
jmp    1185 <main+0x45>
lea    0xe99(%rip),%rdi
xor    %esi,%esi
call   1040 <sha1@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Sha1 hash test\00"
@.str.1 = [14 x i8] c"Hash of \22%s\22\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 2
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = call i8* @sha1(i8* %16, i32 %20)
%22 = call i32 @puts(i8* %21)
br label %26
23: ; preds = %2
%24 = call i8* @sha1(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 0)
%25 = call i32 @puts(i8* %24)
br label %26
26: ; preds = %23, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Sha1 hash test\00"
@.str.1 = [14 x i8] c"Hash of \22%s\22\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %6
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call i8* @sha1(i8* %9, i32 %10)
br label %14
12: ; preds = %2
%13 = tail call i8* @sha1(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %14
14: ; preds = %12, %5
%15 = phi i8* [ %13, %12 ], [ %11, %5 ]
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
ret i32 0
}