#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 */
scalar_t__ RAND_MAX;
int floor(double);
int getpid();
scalar_t__ malloc(int);
unsigned int rand();
int /*<<< orphan*/ srand(int);
unsigned int strlen(char const *);
int time(int /*<<< orphan*/ *);
char *oauth_gen_nonce() {
  char *nc;
  static int rndinit = 1;
  const char *chars = "abcdefghijklmnopqrstuvwxyz"
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                      "0123456789_";
  unsigned int max = strlen(chars);
  int i, len;
  if (rndinit) {
    srand(time(NULL) * getpid());
    rndinit = 0;
  }
  len = 15 + floor(rand() * 16.0 / (double)RAND_MAX);
  nc = (char *)malloc((len + 1) * sizeof(char));
  for (i = 0; i < len; i++) {
    nc[i] = chars[rand() % max];
  }
  nc[i] = '\0';
  return (nc);
}


x86 assembly (clang, -O0):
<oauth_gen_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe89(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,0x2ec2(%rip)
je     11c4 <oauth_gen_nonce+0x54>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%edi
imul   %eax,%edi
call   1050 <srand@plt>
movl   $0x0,0x2e94(%rip)
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%eax
cvtsi2sd %rax,%xmm0
movsd  0xe26(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e03(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   1080 <floor@plt>
add    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1259 <oauth_gen_nonce+0xe9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
xor    %edx,%edx
divl   -0x14(%rbp)
mov    -0x28(%rbp),%rax
mov    %edx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <oauth_gen_nonce+0xa7>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oauth_gen_nonce>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe86(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
cmpb   $0x0,0x2ecc(%rip)
jne    11b7 <oauth_gen_nonce+0x47>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
imul   %eax,%ebx
mov    %ebx,%edi
call   1050 <srand@plt>
movb   $0x1,0x2ea9(%rip)
xor    %r12d,%r12d
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe30(%rip),%xmm0
mov    0x2e11(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %eax,%ebp
lea    0x10(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%r13
cmp    $0xfffffff2,%ebp
jl     1232 <oauth_gen_nonce+0xc2>
add    $0xe,%ebp
test   %ebp,%ebp
cmovle %r12d,%ebp
add    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1090 <rand@plt>
xor    %edx,%edx
div    %r15d
movzbl (%rdx,%r14,1),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1210 <oauth_gen_nonce+0xa0>
mov    %rbp,%r12
movb   $0x0,0x0(%r13,%r12,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@oauth_gen_nonce.rndinit = internal global i32 1
@.str = [64 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\00"
@RAND_MAX = global i64 0
define i8* @oauth_gen_nonce() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* @oauth_gen_nonce.rndinit
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = call i32 @time(i32* null)
%12 = call i32 (...) @getpid()
%13 = mul nsw i32 %11, %12
%14 = call i32 @srand(i32 %13)
store i32 0, i32* @oauth_gen_nonce.rndinit
br label %15
15: ; preds = %10, %0
%16 = call i32 (...) @rand()
%17 = uitofp i32 %16 to double
%18 = fmul double %17, 1.600000e+01
%19 = load i64, i64* @RAND_MAX
%20 = sitofp i64 %19 to double
%21 = fdiv double %18, %20
%22 = call i32 @floor(double %21)
%23 = add nsw i32 15, %22
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %1
store i32 0, i32* %4
br label %31
31: ; preds = %47, %15
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i8*, i8** %2
%37 = call i32 (...) @rand()
%38 = load i32, i32* %3
%39 = urem i32 %37, %38
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
%42 = load i8, i8* %41
%43 = load i8*, i8** %1
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %31
50: ; preds = %31
%51 = load i8*, i8** %1
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i8*, i8** %1
ret i8* %55
}

LLVM IR (-O2):
@oauth_gen_nonce.rndinit = internal unnamed_addr global i1 false
@.str = [64 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\00"
@RAND_MAX = global i64 0
define i8* @oauth_gen_nonce() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%2 = load i1, i1* @oauth_gen_nonce.rndinit
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 (...) @getpid()
%6 = mul nsw i32 %5, %4
%7 = tail call i32 @srand(i32 %6)
store i1 true, i1* @oauth_gen_nonce.rndinit
br label %8
8: ; preds = %3, %0
%9 = tail call i32 (...) @rand()
%10 = uitofp i32 %9 to double
%11 = fmul double %10, 1.600000e+01
%12 = load i64, i64* @RAND_MAX
%13 = sitofp i64 %12 to double
%14 = fdiv double %11, %13
%15 = tail call i32 @floor(double %14)
%16 = add nsw i32 %15, 16
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp sgt i32 %15, -15
br i1 %19, label %20, label %37
20: ; preds = %8
%21 = add i32 %15, 14
%22 = call i32 @llvm.smax.i32(i32 %21, i32 0)
%23 = add nuw i32 %22, 1
%24 = zext i32 %23 to i64
br label %25
25: ; preds = %20, %25
%26 = phi i64 [ 0, %20 ], [ %33, %25 ]
%27 = tail call i32 (...) @rand()
%28 = urem i32 %27, %1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [64 x i8], [64 x i8]* @.str, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %18, i64 %26
store i8 %31, i8* %32
%33 = add nuw nsw i64 %26, 1
%34 = icmp eq i64 %33, %24
br i1 %34, label %35, label %25
35: ; preds = %25
%36 = zext i32 %23 to i64
br label %37
37: ; preds = %8, %35
%38 = phi i64 [ %36, %35 ], [ 0, %8 ]
%39 = getelementptr inbounds i8, i8* %18, i64 %38
store i8 0, i8* %39
ret i8* %18
}