#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*/ iks_sha(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  struct lala {
    char *str;
    char *hash;
  } known_hashes[] = {
      {"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"},
      {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
       "84983e441c3bd26ebaae4aa1f95129e5e54670f1"},
      {NULL, NULL}};
  int i = 0;
  char buf[42];
  while (known_hashes[i].str) {
    iks_sha(known_hashes[i].str, buf);
    if (strcmp(buf, known_hashes[i].hash) != 0) {
      printf("SHA1 hash of \"%s\"\n", known_hashes[i].str);
      printf(" Result:   %s\n", buf);
      printf(" Expected: %s\n", known_hashes[i].hash);
      return 1;
    }
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe93(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe8c(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xed8(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
je     125a <main+0x11a>
movslq -0x44(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
lea    -0x70(%rbp),%rsi
call   1060 <iks_sha@plt>
lea    -0x70(%rbp),%rdi
movslq -0x44(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     124c <main+0x10c>
movslq -0x44(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
movslq -0x44(%rbp),%rcx
lea    -0x40(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1261 <main+0x121>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1199 <main+0x59>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xeb6(%rip),%r15
mov    %r15,(%rsp)
lea    0xeaf(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rbx
lea    0xec7(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xef4(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0x30(%rsp),%r14
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <iks_sha@plt>
mov    -0x8(%rbx),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11af <main+0x7f>
mov    (%rbx),%r15
add    $0x10,%rbx
test   %r15,%r15
jne    1180 <main+0x50>
xor    %eax,%eax
jmp    11e3 <main+0xb3>
lea    0xed9(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lala = type { i8*, i8* }
@.str = [4 x i8] c"abc\00"
@.str.1 = [41 x i8] c"a9993e364706816aba3e25717850c26c9cd0d89d\00"
@.str.2 = [57 x i8] c"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\00"
@.str.3 = [41 x i8] c"84983e441c3bd26ebaae4aa1f95129e5e54670f1\00"
@.str.4 = [19 x i8] c"SHA1 hash of \22%s\22\0A\00"
@.str.5 = [15 x i8] c" Result: %s\0A\00"
@.str.6 = [15 x i8] c" Expected: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x %struct.lala]
%7 = alloca i32
%8 = alloca [42 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [3 x %struct.lala]* %6 to i8*
%10 = bitcast i8* %9 to [3 x %struct.lala]*
%11 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %10, i32 0, i32 0
%12 = getelementptr inbounds %struct.lala, %struct.lala* %11, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds %struct.lala, %struct.lala* %11, i32 0, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %10, i32 0, i32 1
%15 = getelementptr inbounds %struct.lala, %struct.lala* %14, i32 0, i32 0
store i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds %struct.lala, %struct.lala* %14, i32 0, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i32 0, i32 0), i8** %16
store i32 0, i32* %7
br label %17
17: ; preds = %55, %2
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %6, i64 0, i64 %19
%21 = getelementptr inbounds %struct.lala, %struct.lala* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %58
24: ; preds = %17
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %6, i64 0, i64 %26
%28 = getelementptr inbounds %struct.lala, %struct.lala* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [42 x i8], [42 x i8]* %8, i64 0, i64 0
%31 = call i32 @iks_sha(i8* %29, i8* %30)
%32 = getelementptr inbounds [42 x i8], [42 x i8]* %8, i64 0, i64 0
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %6, i64 0, i64 %34
%36 = getelementptr inbounds %struct.lala, %struct.lala* %35, i32 0, i32 1
%37 = load i8*, i8** %36
%38 = call i64 @strcmp(i8* %32, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %55
40: ; preds = %24
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %6, i64 0, i64 %42
%44 = getelementptr inbounds %struct.lala, %struct.lala* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds [42 x i8], [42 x i8]* %8, i64 0, i64 0
%48 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %6, i64 0, i64 %50
%52 = getelementptr inbounds %struct.lala, %struct.lala* %51, i32 0, i32 1
%53 = load i8*, i8** %52
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %53)
store i32 1, i32* %3
br label %59
55: ; preds = %24
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %17
58: ; preds = %17
store i32 0, i32* %3
br label %59
59: ; preds = %58, %40
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.lala = type { i8*, i8* }
@.str = [4 x i8] c"abc\00"
@.str.1 = [41 x i8] c"a9993e364706816aba3e25717850c26c9cd0d89d\00"
@.str.2 = [57 x i8] c"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\00"
@.str.3 = [41 x i8] c"84983e441c3bd26ebaae4aa1f95129e5e54670f1\00"
@.str.4 = [19 x i8] c"SHA1 hash of \22%s\22\0A\00"
@.str.5 = [15 x i8] c" Result: %s\0A\00"
@.str.6 = [15 x i8] c" Expected: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x %struct.lala]
%4 = alloca [42 x i8]
%5 = bitcast [3 x %struct.lala]* %3 to i8*
%6 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 2
%7 = bitcast %struct.lala* %6 to i8*
%8 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 0, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 1, i32 1
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [42 x i8], [42 x i8]* %4, i64 0, i64 0
br label %17
13: ; preds = %17
%14 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 %25, i32 0
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %30, label %17
17: ; preds = %2, %13
%18 = phi i64 [ 0, %2 ], [ %25, %13 ]
%19 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %2 ], [ %15, %13 ]
%20 = call i32 @iks_sha(i8* %19, i8* %12)
%21 = getelementptr inbounds [3 x %struct.lala], [3 x %struct.lala]* %3, i64 0, i64 %18, i32 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %12, i8* %22)
%24 = icmp eq i64 %23, 0
%25 = add nuw i64 %18, 1
br i1 %24, label %13, label %26
26: ; preds = %17
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %22)
br label %30
30: ; preds = %13, %26
%31 = phi i32 [ 1, %26 ], [ 0, %13 ]
ret i32 %31
}