#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exitmsg(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int init_salt(int saltsize, unsigned char *salt, int fixedsalt) {
  if (fixedsalt) {
    memset(salt, 0, saltsize);
  } else {
    int fd = open("/dev/urandom", O_RDONLY);
    if (read(fd, salt, saltsize) != saltsize) {
      exitmsg("piped_child: %s\n", strerror(errno));
    }
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<init_salt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118f <init_salt+0x2f>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11e3 <init_salt+0x83>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1050 <read@plt>
cmp    -0x4(%rbp),%eax
je     11db <init_salt+0x7b>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1060 <exitmsg@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_salt>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
test   %edx,%edx
je     117b <init_salt+0x1b>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
jmp    11c7 <init_salt+0x67>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
cmp    %ebp,%eax
je     11bf <init_salt+0x5f>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
call   1060 <exitmsg@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"piped_child: %s\0A\00"
@errno = global i32 0
define i32 @init_salt(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = load i32, i32* %4
%13 = call i32 @memset(i8* %11, i32 0, i32 %12)
br label %30
14: ; preds = %3
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = load i8*, i8** %5
%19 = load i32, i32* %4
%20 = call i32 @read(i32 %17, i8* %18, i32 %19)
%21 = load i32, i32* %4
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @exitmsg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %14
%28 = load i32, i32* %7
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"piped_child: %s\0A\00"
@errno = global i32 0
define i32 @init_salt(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @memset(i8* %1, i32 0, i32 %0)
br label %18
7: ; preds = %3
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @read(i32 %9, i8* %1, i32 %0)
%11 = icmp eq i32 %10, %0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @exitmsg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %7
%17 = tail call i32 @close(i32 %9)
br label %18
18: ; preds = %16, %5
ret i32 0
}