#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 */
struct atsha_handle {
  int dummy;
};

/* Variables and functions */
unsigned char *generate_answer_packet(unsigned char *, int);
int emul_random(struct atsha_handle *handle, unsigned char *raw_packet,
                unsigned char **answer) {
  (void)raw_packet;
  (void)handle;
  unsigned char data[] = {0x55, 0xE3, 0xD9, 0x65, 0x6A, 0x82, 0x69, 0x33,
                          0xB2, 0xAF, 0x9B, 0xCA, 0x64, 0x5C, 0x49, 0x0D,
                          0x09, 0x27, 0xC3, 0x82, 0x0C, 0x32, 0x58, 0xBC,
                          0x8D, 0x23, 0xEE, 0xC4, 0x04, 0xF3, 0xC4, 0x14};
  (*answer) = generate_answer_packet(data, 32);
  if ((*answer) == NULL)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<emul_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xed2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xecf(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xecc(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1030 <generate_answer_packet@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1182 <emul_random+0x72>
movl   $0x1,-0x4(%rbp)
jmp    1189 <emul_random+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emul_random>:
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rbx
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x20,%esi
call   1030 <generate_answer_packet@plt>
mov    %rax,(%rbx)
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.atsha_handle = type { i32 }
@__const.emul_random.data = [32 x i8] c"U\E3\D9ej\82i3\B2\AF\9B\CAd\\I\0D\09'\C3\82\0C2X\BC\8D#\EE\C4\04\F3\C4\14"
define i32 @emul_random(%struct.atsha_handle* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.atsha_handle*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca [32 x i8]
store %struct.atsha_handle* %0, %struct.atsha_handle** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%9 = load i8*, i8** %6
%10 = load %struct.atsha_handle*, %struct.atsha_handle** %5
%11 = bitcast [32 x i8]* %8 to i8*
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%13 = call i8* @generate_answer_packet(i8* %12, i32 32)
%14 = load i8**, i8*** %7
store i8* %13, i8** %14
%15 = load i8**, i8*** %7
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 1, i32* %4
br label %20
19: ; preds = %3
store i32 0, i32* %4
br label %20
20: ; preds = %19, %18
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.atsha_handle = type { i32 }
@__const.emul_random.data = [32 x i8] c"U\E3\D9ej\82i3\B2\AF\9B\CAd\\I\0D\09'\C3\82\0C2X\BC\8D#\EE\C4\04\F3\C4\14"
define i32 @emul_random(%struct.atsha_handle* nocapture readnone %0, i8* nocapture readnone %1, i8** nocapture writeonly %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = call i8* @generate_answer_packet(i8* %5, i32 32)
store i8* %6, i8** %2
%7 = icmp eq i8* %6, null
%8 = zext i1 %7 to i32
ret i32 %8
}