#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 uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void genSalt(uint8_t *salt) {
  FILE *randFile = fopen("/dev/urandom", "r");
  if (randFile == NULL) {
    fprintf(stderr, "Unable to open random /dev/urandom\n");
    exit(1);
  }
  for (uint32_t i = 0; i < 16; i++) {
    salt[i] = getc(randFile);
  }
  fclose(randFile);
}


x86 assembly (clang, -O0):
<genSalt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <genSalt+0x4d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11d2 <genSalt+0x82>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <genSalt+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genSalt>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1244 <genSalt+0xf4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x4(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x8(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0xc(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x10(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x14(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x18(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x1c(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x20(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x24(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x28(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x2c(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x30(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x34(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x38(%r14)
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,0x3c(%r14)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Unable to open random /dev/urandom\0A\00"
define void @genSalt(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
store i32 0, i32* %4
br label %13
13: ; preds = %23, %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 16
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32*, i32** %3
%18 = call i32 @getc(i32* %17)
%19 = load i32*, i32** %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 %18, i32* %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %13
26: ; preds = %13
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Unable to open random /dev/urandom\0A\00"
define void @genSalt(i32* nocapture writeonly %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %37, label %4
4: ; preds = %1
%5 = tail call i32 @getc(i32* %2)
store i32 %5, i32* %0
%6 = tail call i32 @getc(i32* %2)
%7 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %6, i32* %7
%8 = tail call i32 @getc(i32* %2)
%9 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %8, i32* %9
%10 = tail call i32 @getc(i32* %2)
%11 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %10, i32* %11
%12 = tail call i32 @getc(i32* %2)
%13 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %12, i32* %13
%14 = tail call i32 @getc(i32* %2)
%15 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %14, i32* %15
%16 = tail call i32 @getc(i32* %2)
%17 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %16, i32* %17
%18 = tail call i32 @getc(i32* %2)
%19 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %18, i32* %19
%20 = tail call i32 @getc(i32* %2)
%21 = getelementptr inbounds i32, i32* %0, i64 8
store i32 %20, i32* %21
%22 = tail call i32 @getc(i32* %2)
%23 = getelementptr inbounds i32, i32* %0, i64 9
store i32 %22, i32* %23
%24 = tail call i32 @getc(i32* %2)
%25 = getelementptr inbounds i32, i32* %0, i64 10
store i32 %24, i32* %25
%26 = tail call i32 @getc(i32* %2)
%27 = getelementptr inbounds i32, i32* %0, i64 11
store i32 %26, i32* %27
%28 = tail call i32 @getc(i32* %2)
%29 = getelementptr inbounds i32, i32* %0, i64 12
store i32 %28, i32* %29
%30 = tail call i32 @getc(i32* %2)
%31 = getelementptr inbounds i32, i32* %0, i64 13
store i32 %30, i32* %31
%32 = tail call i32 @getc(i32* %2)
%33 = getelementptr inbounds i32, i32* %0, i64 14
store i32 %32, i32* %33
%34 = tail call i32 @getc(i32* %2)
%35 = getelementptr inbounds i32, i32* %0, i64 15
store i32 %34, i32* %35
%36 = tail call i32 @fclose(i32* %2)
ret void
37: ; preds = %1
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
}