#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CutStr(char *, int);
int /*<<< orphan*/ MDString(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(unsigned int);
int hexnum2(char dst[]) {
  FILE *fp;
  char x[300], x1[129], md[33];
  unsigned int hex;
  fp = fopen("/dev/urandom", "r");
  if (fp == NULL)
    return 0;
  fread(x, 128, 1, fp);
  x[128] = 0;
  fclose(fp);
  strcpy(md, MDString(x));
  CutStr(md, 8);
  sscanf(md, "%x", &hex);
  usleep(hex % 100000);
  fp = fopen("/dev/urandom", "r");
  fread(x1, 128, 1, fp);
  x1[128] = 0;
  fclose(fp);
  strcat(x, x1);
  strcpy(x, MDString(x));
  CutStr(x, 8);
  sscanf(x, "%x", &hex);
  while (hex < 0x40000000) {
    hex += 0x1000000;
  }
  while (hex > 0x50000000) {
    hex -= 0x1000000;
  }
  sprintf(dst, "%x", hex);
  return 1;
}


x86 assembly (clang, -O0):
<hexnum2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe4a(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dd <hexnum2+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1385 <hexnum2+0x1e5>
lea    -0x150(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
movb   $0x0,-0xd0(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <MDString@plt>
mov    -0x228(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
mov    $0x8,%esi
call   1070 <CutStr@plt>
lea    -0x210(%rbp),%rdi
lea    0xdc1(%rip),%rsi
lea    -0x214(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x214(%rbp),%eax
mov    $0x186a0,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%edi
call   10c0 <usleep@plt>
lea    0xd89(%rip),%rdi
lea    0xd8f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1e0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
movb   $0x0,-0x160(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x150(%rbp),%rdi
lea    -0x1e0(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x150(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <MDString@plt>
mov    -0x220(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x150(%rbp),%rdi
mov    $0x8,%esi
call   1070 <CutStr@plt>
lea    -0x150(%rbp),%rdi
lea    0xd04(%rip),%rsi
lea    -0x214(%rbp),%rdx
call   1080 <sscanf@plt>
cmpl   $0x40000000,-0x214(%rbp)
jae    133d <hexnum2+0x19d>
mov    -0x214(%rbp),%eax
add    $0x1000000,%eax
mov    %eax,-0x214(%rbp)
jmp    1317 <hexnum2+0x177>
jmp    1342 <hexnum2+0x1a2>
cmpl   $0x50000000,-0x214(%rbp)
jbe    1368 <hexnum2+0x1c8>
mov    -0x214(%rbp),%eax
sub    $0x1000000,%eax
mov    %eax,-0x214(%rbp)
jmp    1342 <hexnum2+0x1a2>
mov    -0x10(%rbp),%rdi
mov    -0x214(%rbp),%edx
lea    0xc96(%rip),%rsi
call   10b0 <sprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexnum2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
lea    0xe45(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     133e <hexnum2+0x19e>
mov    %rax,%rbx
lea    0xd0(%rsp),%r13
mov    %r13,%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
movb   $0x0,0x150(%rsp)
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
call   1050 <MDString@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <CutStr@plt>
lea    0xde4(%rip),%r15
lea    0xc(%rsp),%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <sscanf@plt>
mov    0xc(%rsp),%edi
mov    %edi,%eax
shr    $0x5,%eax
imul   $0xa7c5ac5,%rax,%rax
shr    $0x27,%rax
imul   $0x186a0,%eax,%eax
sub    %eax,%edi
call   10c0 <usleep@plt>
lea    0xd9a(%rip),%rdi
lea    0xda0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
movb   $0x0,0xc0(%rsp)
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <strcat@plt>
mov    %r13,%rdi
call   1050 <MDString@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    $0x8,%esi
call   1070 <CutStr@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <sscanf@plt>
mov    0xc(%rsp),%edx
cmp    $0x3fffffff,%edx
ja     1307 <hexnum2+0x167>
xor    %eax,%eax
mov    $0x3f000000,%ecx
sub    %edx,%ecx
cmovb  %eax,%ecx
add    $0xffffff,%ecx
and    $0xff000000,%ecx
add    %ecx,%edx
add    $0x1000000,%edx
mov    %edx,0xc(%rsp)
cmp    $0x50000001,%edx
jb     1328 <hexnum2+0x188>
lea    -0x50000001(%rdx),%eax
and    $0xff000000,%eax
neg    %eax
add    %eax,%edx
add    $0xff000000,%edx
mov    %edx,0xc(%rsp)
lea    0xce0(%rip),%rsi
mov    %r14,%rdi
call   10b0 <sprintf@plt>
mov    $0x1,%eax
jmp    1340 <hexnum2+0x1a0>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
define i32 @hexnum2(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [300 x i8]
%6 = alloca [129 x i8]
%7 = alloca [33 x i8]
%8 = alloca i32
store i8* %0, i8** %3
%9 = 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* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %66
13: ; preds = %1
%14 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32 @fread(i8* %14, i32 128, i32 1, i32* %15)
%17 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 128
store i8 0, i8* %17
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = getelementptr inbounds [33 x i8], [33 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%22 = call i32 @MDString(i8* %21)
%23 = call i32 @strcpy(i8* %20, i32 %22)
%24 = getelementptr inbounds [33 x i8], [33 x i8]* %7, i64 0, i64 0
%25 = call i32 @CutStr(i8* %24, i32 8)
%26 = getelementptr inbounds [33 x i8], [33 x i8]* %7, i64 0, i64 0
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%28 = load i32, i32* %8
%29 = urem i32 %28, 100000
%30 = call i32 @usleep(i32 %29)
%31 = 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* %31, i32** %4
%32 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%33 = load i32*, i32** %4
%34 = call i32 @fread(i8* %32, i32 128, i32 1, i32* %33)
%35 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 128
store i8 0, i8* %35
%36 = load i32*, i32** %4
%37 = call i32 @fclose(i32* %36)
%38 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%39 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
%41 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%43 = call i32 @MDString(i8* %42)
%44 = call i32 @strcpy(i8* %41, i32 %43)
%45 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%46 = call i32 @CutStr(i8* %45, i32 8)
%47 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%48 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
br label %49
49: ; preds = %52, %13
%50 = load i32, i32* %8
%51 = icmp ult i32 %50, 1073741824
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* %8
%54 = add i32 %53, 16777216
store i32 %54, i32* %8
br label %49
55: ; preds = %49
br label %56
56: ; preds = %59, %55
%57 = load i32, i32* %8
%58 = icmp ugt i32 %57, 1342177280
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %8
%61 = sub i32 %60, 16777216
store i32 %61, i32* %8
br label %56
62: ; preds = %56
%63 = load i8*, i8** %3
%64 = load i32, i32* %8
%65 = call i32 @sprintf(i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %64)
store i32 1, i32* %2
br label %66
66: ; preds = %62, %12
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
define i32 @hexnum2(i8* nocapture writeonly %0) {
%2 = alloca [300 x i8]
%3 = alloca [129 x i8]
%4 = alloca [33 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = 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))
%11 = icmp eq i32* %10, null
br i1 %11, label %52, label %12
12: ; preds = %1
%13 = call i32 @fread(i8* %6, i32 128, i32 1, i32* %10)
%14 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 128
store i8 0, i8* %14
%15 = tail call i32 @fclose(i32* %10)
%16 = call i32 @MDString(i8* %6)
%17 = call i32 @strcpy(i8* %8, i32 %16)
%18 = call i32 @CutStr(i8* %8, i32 8)
%19 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%20 = load i32, i32* %5
%21 = urem i32 %20, 100000
%22 = call i32 @usleep(i32 %21)
%23 = 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))
%24 = call i32 @fread(i8* %7, i32 128, i32 1, i32* %23)
%25 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 128
store i8 0, i8* %25
%26 = call i32 @fclose(i32* %23)
%27 = call i32 @strcat(i8* %6, i8* %7)
%28 = call i32 @MDString(i8* %6)
%29 = call i32 @strcpy(i8* %6, i32 %28)
%30 = call i32 @CutStr(i8* %6, i32 8)
%31 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%32 = load i32, i32* %5
%33 = icmp ult i32 %32, 1073741824
br i1 %33, label %34, label %41
34: ; preds = %12
%35 = call i32 @llvm.umax.i32(i32 %32, i32 1056964608)
%36 = add i32 %35, 16777215
%37 = sub i32 %36, %32
%38 = and i32 %37, -16777216
%39 = add i32 %32, %38
%40 = add i32 %39, 16777216
store i32 %40, i32* %5
br label %41
41: ; preds = %34, %12
%42 = phi i32 [ %40, %34 ], [ %32, %12 ]
%43 = icmp ugt i32 %42, 1342177280
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = add i32 %42, -1342177281
%46 = and i32 %45, -16777216
%47 = add i32 %42, -16777216
%48 = sub i32 %47, %46
store i32 %48, i32* %5
br label %49
49: ; preds = %44, %41
%50 = phi i32 [ %48, %44 ], [ %42, %41 ]
%51 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %1, %49
%53 = phi i32 [ 1, %49 ], [ 0, %1 ]
ret i32 %53
}