#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 unsigned int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ set_hash_addr(unsigned int *, unsigned int);
int /*<<< orphan*/ thash(unsigned char *, unsigned char *, int,
                         unsigned char const *, unsigned int *);
void gen_chain(unsigned char *out, const unsigned char *in, unsigned int start,
               unsigned int steps, const unsigned char *pub_seed,
               uint32_t addr[8]) {
  uint32_t i;
  memcpy(out, in, 16);
  for (i = start; i < (start + steps) && i < 16; i++) {
    set_hash_addr(addr, i);
    thash(out, out, 1, pub_seed, addr);
  }
}


x86 assembly (clang, -O0):
<gen_chain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x14(%rbp),%edx
add    -0x18(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x2d(%rbp)
jae    1186 <gen_chain+0x56>
cmpl   $0x10,-0x2c(%rbp)
setb   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1196 <gen_chain+0x66>
jmp    11ca <gen_chain+0x9a>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <set_hash_addr@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0x1,%edx
call   1030 <thash@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1166 <gen_chain+0x36>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_chain>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9,%r12
mov    %r8,%r14
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rdi,%rbx
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    %ebp,%r15d
cmp    %ebp,%r15d
jbe    118f <gen_chain+0x5f>
cmp    $0xf,%ebp
ja     118f <gen_chain+0x5f>
nopl   (%rax)
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <set_hash_addr@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
mov    %r12,%r8
call   1030 <thash@plt>
lea    0x1(%rbp),%eax
cmp    %r15d,%eax
jae    118f <gen_chain+0x5f>
cmp    $0xf,%ebp
mov    %eax,%ebp
jb     1160 <gen_chain+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gen_chain(i8* %0, i8* %1, i32 %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32* %5, i32** %12
%14 = load i8*, i8** %7
%15 = load i8*, i8** %8
%16 = call i32 @memcpy(i8* %14, i8* %15, i32 16)
%17 = load i32, i32* %9
store i32 %17, i32* %13
br label %18
18: ; preds = %38, %6
%19 = load i32, i32* %13
%20 = load i32, i32* %9
%21 = load i32, i32* %10
%22 = add i32 %20, %21
%23 = icmp ult i32 %19, %22
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %13
%26 = icmp ult i32 %25, 16
br label %27
27: ; preds = %24, %18
%28 = phi i1 [ false, %18 ], [ %26, %24 ]
br i1 %28, label %29, label %41
29: ; preds = %27
%30 = load i32*, i32** %12
%31 = load i32, i32* %13
%32 = call i32 @set_hash_addr(i32* %30, i32 %31)
%33 = load i8*, i8** %7
%34 = load i8*, i8** %7
%35 = load i8*, i8** %11
%36 = load i32*, i32** %12
%37 = call i32 @thash(i8* %33, i8* %34, i32 1, i8* %35, i32* %36)
br label %38
38: ; preds = %29
%39 = load i32, i32* %13
%40 = add i32 %39, 1
store i32 %40, i32* %13
br label %18
41: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @gen_chain(i8* %0, i8* %1, i32 %2, i32 %3, i8* %4, i32* %5) {
%7 = tail call i32 @memcpy(i8* %0, i8* %1, i32 16)
%8 = add i32 %3, %2
%9 = icmp ugt i32 %8, %2
%10 = icmp ult i32 %2, 16
%11 = and i1 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %6, %12
%13 = phi i32 [ %16, %12 ], [ %2, %6 ]
%14 = tail call i32 @set_hash_addr(i32* %5, i32 %13)
%15 = tail call i32 @thash(i8* %0, i8* %0, i32 1, i8* %4, i32* %5)
%16 = add nuw nsw i32 %13, 1
%17 = icmp ult i32 %16, %8
%18 = icmp ult i32 %13, 15
%19 = and i1 %17, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %6
ret void
}