#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 */
double RAND_MAX;
double rand();
char *random_secret(void) {
  static char secret[41];
  int i, r;
  for (i = 0; i < 40; i++) {
    r = (int)(36.0 * rand() / RAND_MAX);
    secret[i] = (r >= 0 && r <= 9) ? (r + 48) : (r + 87);
  }
  secret[40] = '\0';
  return secret;
}


x86 assembly (clang, -O0):
<random_secret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x28,-0x4(%rbp)
jge    119d <random_secret+0x8d>
mov    $0x0,%al
call   1030 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xec5(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2ea2(%rip),%rax
divsd  (%rax),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1173 <random_secret+0x63>
cmpl   $0x9,-0x8(%rbp)
jg     1173 <random_secret+0x63>
mov    -0x8(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    117c <random_secret+0x6c>
mov    -0x8(%rbp),%eax
add    $0x57,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,%dl
movslq -0x4(%rbp),%rcx
lea    0x2eb4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <random_secret+0xf>
movb   $0x0,0x2ec4(%rip)
lea    0x2e95(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_secret>:
push   %r15
push   %r14
push   %rbx
mov    0x2ecc(%rip),%r14
lea    0x2f1d(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <rand@plt>
mulsd  0xec1(%rip),%xmm0
divsd  (%r14),%xmm0
cvttsd2si %xmm0,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
cmovae %ecx,%edx
mov    %dl,(%rbx,%r15,1)
add    $0x1,%rbx
cmp    $0x28,%rbx
jne    1130 <random_secret+0x20>
movb   $0x0,0x2eff(%rip)
lea    0x2ed0(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@random_secret.secret = internal global [41 x i8] zeroinitializer
@RAND_MAX = global double 0.000000e+00
define i8* @random_secret() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %29, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 40
br i1 %5, label %6, label %32
6: ; preds = %3
%7 = call double (...) @rand()
%8 = fmul double 3.600000e+01, %7
%9 = load double, double* @RAND_MAX
%10 = fdiv double %8, %9
%11 = fptosi double %10 to i32
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %6
%15 = load i32, i32* %2
%16 = icmp sle i32 %15, 9
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 48
br label %23
20: ; preds = %14, %6
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 87
br label %23
23: ; preds = %20, %17
%24 = phi i32 [ %19, %17 ], [ %22, %20 ]
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [41 x i8], [41 x i8]* @random_secret.secret, i64 0, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %23
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
br label %3
32: ; preds = %3
store i8 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @random_secret.secret, i64 0, i64 40)
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @random_secret.secret, i64 0, i64 0)
}

LLVM IR (-O2):
@random_secret.secret = internal global [41 x i8] zeroinitializer
@RAND_MAX = global double 0.000000e+00
define i8* @random_secret() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 0, %0 ], [ %13, %1 ]
%3 = tail call double (...) @rand()
%4 = fmul double %3, 3.600000e+01
%5 = load double, double* @RAND_MAX
%6 = fdiv double %4, %5
%7 = fptosi double %6 to i32
%8 = icmp ult i32 %7, 10
%9 = select i1 %8, i32 48, i32 87
%10 = add nsw i32 %9, %7
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds [41 x i8], [41 x i8]* @random_secret.secret, i64 0, i64 %2
store i8 %11, i8* %12
%13 = add nuw nsw i64 %2, 1
%14 = icmp eq i64 %13, 40
br i1 %14, label %15, label %1
15: ; preds = %1
store i8 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @random_secret.secret, i64 0, i64 40)
ret i8* getelementptr inbounds ([41 x i8], [41 x i8]* @random_secret.secret, i64 0, i64 0)
}