#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 lrand48();
int /*<<< orphan*/ srand48(intptr_t);
intptr_t time(int /*<<< orphan*/ *);
void zrand_libc_rand48(void *out, size_t n, void *statep) {
  static char inited = 0;
  long int r0, r1;
  unsigned char *buf = out;
  if (!inited) {
    inited = 1;
    srand48((intptr_t)out | time(NULL));
  }
  while (n--) {
    r0 = lrand48() & 15;
    r1 = lrand48() & 15;
    buf[n] = (unsigned char)((r0 << 4) | r1);
  }
  (void)statep;
}


x86 assembly (clang, -O0):
<zrand_libc_rand48>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpb   $0x0,0x2ee6(%rip)
jne    117d <zrand_libc_rand48+0x4d>
movb   $0x1,0x2ed9(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <time@plt>
mov    -0x38(%rbp),%rdi
or     %rax,%rdi
call   1050 <srand48@plt>
jmp    1182 <zrand_libc_rand48+0x52>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     11d9 <zrand_libc_rand48+0xa9>
mov    $0x0,%al
call   1040 <lrand48@plt>
and    $0xf,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <lrand48@plt>
and    $0xf,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x4,%rax
or     -0x28(%rbp),%rax
mov    %al,%dl
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1182 <zrand_libc_rand48+0x52>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zrand_libc_rand48>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
cmpb   $0x0,0x2ef8(%rip)
jne    115c <zrand_libc_rand48+0x2c>
movb   $0x1,0x2eef(%rip)
xor    %edi,%edi
call   1030 <time@plt>
or     %r14,%rax
mov    %rax,%rdi
call   1050 <srand48@plt>
test   %rbx,%rbx
je     1193 <zrand_libc_rand48+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <lrand48@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <lrand48@plt>
and    $0xf,%eax
shl    $0x4,%ebp
or     %eax,%ebp
mov    %bpl,-0x1(%r14,%rbx,1)
add    $0xffffffffffffffff,%rbx
jne    1170 <zrand_libc_rand48+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@zrand_libc_rand48.inited = internal global i8 0
define void @zrand_libc_rand48(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
store i8* %10, i8** %9
%11 = load i8, i8* @zrand_libc_rand48.inited
%12 = icmp ne i8 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %3
store i8 1, i8* @zrand_libc_rand48.inited
%14 = load i8*, i8** %4
%15 = ptrtoint i8* %14 to i64
%16 = call i64 @time(i32* null)
%17 = or i64 %15, %16
%18 = call i32 @srand48(i64 %17)
br label %19
19: ; preds = %13, %3
br label %20
20: ; preds = %24, %19
%21 = load i64, i64* %5
%22 = add i64 %21, -1
store i64 %22, i64* %5
%23 = icmp ne i64 %21, 0
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = call i32 (...) @lrand48()
%26 = and i32 %25, 15
%27 = sext i32 %26 to i64
store i64 %27, i64* %7
%28 = call i32 (...) @lrand48()
%29 = and i32 %28, 15
%30 = sext i32 %29 to i64
store i64 %30, i64* %8
%31 = load i64, i64* %7
%32 = shl i64 %31, 4
%33 = load i64, i64* %8
%34 = or i64 %32, %33
%35 = trunc i64 %34 to i8
%36 = load i8*, i8** %9
%37 = load i64, i64* %5
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 %35, i8* %38
br label %20
39: ; preds = %20
%40 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@zrand_libc_rand48.inited = internal unnamed_addr global i1 false
define void @zrand_libc_rand48(i8* %0, i64 %1, i8* nocapture readnone %2) {
%4 = load i1, i1* @zrand_libc_rand48.inited
br i1 %4, label %10, label %5
5: ; preds = %3
store i1 true, i1* @zrand_libc_rand48.inited
%6 = ptrtoint i8* %0 to i64
%7 = tail call i64 @time(i32* null)
%8 = or i64 %7, %6
%9 = tail call i32 @srand48(i64 %8)
br label %10
10: ; preds = %5, %3
%11 = icmp eq i64 %1, 0
br i1 %11, label %23, label %12
12: ; preds = %10, %12
%13 = phi i64 [ %14, %12 ], [ %1, %10 ]
%14 = add i64 %13, -1
%15 = tail call i32 (...) @lrand48()
%16 = tail call i32 (...) @lrand48()
%17 = and i32 %16, 15
%18 = shl i32 %15, 4
%19 = or i32 %17, %18
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %20, i8* %21
%22 = icmp eq i64 %14, 0
br i1 %22, label %23, label %12
23: ; preds = %12, %10
ret void
}