#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ to64(char *, unsigned char, int);
void makesalt(char salt[32]) {
  int i, fd;
  unsigned char tmp;
  fd = open("/dev/urandom", O_RDONLY);
  for (i = 0; i < 32; i += 1) {
    read(fd, &tmp, sizeof(char));
    to64(&salt[i], tmp, 1);
  }
  close(fd);
  salt[32] = '\0';
}


x86 assembly (clang, -O0):
<makesalt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    11ad <makesalt+0x6d>
mov    -0x10(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    $0x1,%edx
movzbl -0x11(%rbp),%esi
call   1030 <to64@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <makesalt+0x2b>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x20(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makesalt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x7(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
lea    (%r15,%rbx,1),%rdi
movzbl 0x7(%rsp),%esi
mov    $0x1,%edx
call   1030 <to64@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1170 <makesalt+0x30>
mov    %ebp,%edi
call   1040 <close@plt>
movb   $0x0,0x20(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define void @makesalt(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
store i32 0, i32* %3
br label %8
8: ; preds = %20, %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 32
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32, i32* %4
%13 = call i32 @read(i32 %12, i8* %5, i32 1)
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %5
%19 = call i32 @to64(i8* %17, i8 zeroext %18, i32 1)
br label %20
20: ; preds = %11
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %8
23: ; preds = %8
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 32
store i8 0, i8* %27
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define void @makesalt(i8* %0) {
%2 = alloca i8
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %1, %5
%6 = phi i64 [ 0, %1 ], [ %11, %5 ]
%7 = call i32 @read(i32 %4, i8* %2, i32 1)
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %2
%10 = tail call i32 @to64(i8* %8, i8 zeroext %9, i32 1)
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, 32
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = tail call i32 @close(i32 %4)
%15 = getelementptr inbounds i8, i8* %0, i64 32
store i8 0, i8* %15
ret void
}