#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*/ expand_hex(char *, int);
int /*<<< orphan*/ get_random_bytes(char *, int);
int /*<<< orphan*/ log_message(char *, char *, char *, int);
char *malloc(int);
char *generate_nonce(void) {
  char *nonce;
  nonce = malloc(17);
  if (!nonce) {
    log_message("%s: OUT OF MEMORY at %s:%d", "generate_nonce",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/OS2World/APP-SERVER-opennap/"
                "refs/heads/master/util.c",
                190);
    return 0;
  }
  nonce[16] = 0;
  get_random_bytes(nonce, 8);
  expand_hex(nonce, 8);
  return nonce;
}


x86 assembly (clang, -O0):
<generate_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x11,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <generate_nonce+0x4d>
lea    0xe98(%rip),%rdi
lea    0xeac(%rip),%rsi
lea    0xeb4(%rip),%rdx
mov    $0xbe,%ecx
call   1050 <log_message@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <generate_nonce+0x79>
mov    -0x10(%rbp),%rax
movb   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1060 <get_random_bytes@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <expand_hex@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_nonce>:
push   %rbx
mov    $0x11,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1173 <generate_nonce+0x33>
movb   $0x0,0x10(%rbx)
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <get_random_bytes@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <expand_hex@plt>
jmp    1192 <generate_nonce+0x52>
lea    0xe86(%rip),%rdi
lea    0xe9a(%rip),%rsi
lea    0xea2(%rip),%rdx
mov    $0xbe,%ecx
call   1050 <log_message@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%s: OUT OF MEMORY at %s:%d\00"
@.str.1 = [15 x i8] c"generate_nonce\00"
@.str.2 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OS2World/APP-SERVER-opennap/refs/heads/master/util.c\00"
define i8* @generate_nonce() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @malloc(i32 17)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @log_message(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 190)
store i8* null, i8** %1
br label %16
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 16
store i8 0, i8* %10
%11 = load i8*, i8** %2
%12 = call i32 @get_random_bytes(i8* %11, i32 8)
%13 = load i8*, i8** %2
%14 = call i32 @expand_hex(i8* %13, i32 8)
%15 = load i8*, i8** %2
store i8* %15, i8** %1
br label %16
16: ; preds = %8, %6
%17 = load i8*, i8** %1
ret i8* %17
}

LLVM IR (-O2):
@.str = [27 x i8] c"%s: OUT OF MEMORY at %s:%d\00"
@.str.1 = [15 x i8] c"generate_nonce\00"
@.str.2 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OS2World/APP-SERVER-opennap/refs/heads/master/util.c\00"
define i8* @generate_nonce() {
%1 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @log_message(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 190)
br label %9
5: ; preds = %0
%6 = getelementptr inbounds i8, i8* %1, i64 16
store i8 0, i8* %6
%7 = tail call i32 @get_random_bytes(i8* %1, i32 8)
%8 = tail call i32 @expand_hex(i8* %1, i32 8)
br label %9
9: ; preds = %5, %3
ret i8* %1
}