#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 int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ random;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
char *base64_enc(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, int /*<<< orphan*/ *, int);
char *make_nonce(void) {
  uint8_t random[8];
  int fd = open("/dev/random", O_RDONLY);
  if (fd < 0)
    die("could not open /dev/random!");
  (void)(read(fd, random, sizeof(random)) + 1);
  close(fd);
  return base64_enc(random, 8);
}


x86 assembly (clang, -O0):
<make_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1186 <make_nonce+0x36>
lea    0xe8b(%rip),%rdi
call   1070 <die@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1030 <base64_enc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_nonce>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117e <make_nonce+0x2e>
lea    0xe93(%rip),%rdi
call   1070 <die@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %r14,%rdi
mov    $0x8,%esi
call   1030 <base64_enc@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"could not open /dev/random!\00"
define i8* @make_nonce() {
%1 = alloca [8 x i32]
%2 = alloca i32
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* %2
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%12 = call i64 @read(i32 %10, i32* %11, i32 32)
%13 = add nsw i64 %12, 1
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%17 = call i8* @base64_enc(i32* %16, i32 8)
ret i8* %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"could not open /dev/random!\00"
define i8* @make_nonce() {
%1 = alloca [8 x i32]
%2 = bitcast [8 x i32]* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%10 = call i64 @read(i32 %4, i32* %9, i32 32)
%11 = tail call i32 @close(i32 %4)
%12 = call i8* @base64_enc(i32* %9, i32 8)
ret i8* %12
}