#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*/ RAND_bytes(unsigned char *, int);
int /*<<< orphan*/ RAND_cleanup();
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, char, int);
int /*<<< orphan*/ stderr;
unsigned char *abac_generate_serial() {
  unsigned char *serial = (unsigned char *)malloc(sizeof(unsigned char) * 8);
  memset(serial, '\0', 8);
  if (!RAND_bytes(serial, 8)) {
    fprintf(stderr, "RAT, RAN^D out of seeds!!!\n");
    assert(0);
  }
  while (serial[0] == 0)
    RAND_bytes(&serial[0], 1);
  RAND_cleanup();
  return serial;
}


x86 assembly (clang, -O0):
<abac_generate_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
call   1030 <RAND_bytes@plt>
cmp    $0x0,%eax
jne    11b9 <abac_generate_serial+0x59>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1050 <assert@plt>
jmp    11be <abac_generate_serial+0x5e>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    11e1 <abac_generate_serial+0x81>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <RAND_bytes@plt>
jmp    11be <abac_generate_serial+0x5e>
mov    $0x0,%al
call   1080 <RAND_cleanup@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abac_generate_serial>:
push   %rbx
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <RAND_bytes@plt>
test   %eax,%eax
jne    11bd <abac_generate_serial+0x5d>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1050 <assert@plt>
jmp    11bd <abac_generate_serial+0x5d>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <RAND_bytes@plt>
cmpb   $0x0,(%rbx)
je     11b0 <abac_generate_serial+0x50>
xor    %eax,%eax
call   1080 <RAND_cleanup@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"RAT, RAN^D out of seeds!!!\0A\00"
define i8* @abac_generate_serial() {
%1 = alloca i8*
%2 = call i64 @malloc(i32 8)
%3 = inttoptr i64 %2 to i8*
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 8)
%6 = load i8*, i8** %1
%7 = call i32 @RAND_bytes(i8* %6, i32 8)
%8 = icmp ne i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @assert(i32 0)
br label %13
13: ; preds = %9, %0
br label %14
14: ; preds = %20, %13
%15 = load i8*, i8** %1
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i8*, i8** %1
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = call i32 @RAND_bytes(i8* %22, i32 1)
br label %14
24: ; preds = %14
%25 = call i32 (...) @RAND_cleanup()
%26 = load i8*, i8** %1
ret i8* %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"RAT, RAN^D out of seeds!!!\0A\00"
define i8* @abac_generate_serial() {
%1 = tail call i64 @malloc(i32 8)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @memset(i8* %2, i8 signext 0, i32 8)
%4 = tail call i32 @RAND_bytes(i8* %2, i32 8)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @assert(i32 0)
br label %10
10: ; preds = %6, %0
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10, %13
%14 = tail call i32 @RAND_bytes(i8* %2, i32 1)
%15 = load i8, i8* %2
%16 = icmp eq i8 %15, 0
br i1 %16, label %13, label %17
17: ; preds = %13, %10
%18 = tail call i32 (...) @RAND_cleanup()
ret i8* %2
}