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

/* Variables and functions */
double RAND_MAX;
float rand();
void gg_oauth_generate_nonce(char *buf, int len) {
  const char charset[] = "0123456789";
  if (buf == NULL || len < 1)
    return;
  while (len > 1) {
    *buf++ = charset[(unsigned)(((float)sizeof(charset) - 1.0) * rand() /
                                (RAND_MAX + 1.0))];
    len--;
  }
  *buf = 0;
}


x86 assembly (clang, -O0):
<gg_oauth_generate_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeea(%rip),%rax
mov    %rax,-0x17(%rbp)
mov    0xee7(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xedf(%rip),%al
mov    %al,-0xd(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1153 <gg_oauth_generate_nonce+0x43>
cmpl   $0x1,-0xc(%rbp)
jge    1158 <gg_oauth_generate_nonce+0x48>
jmp    11ca <gg_oauth_generate_nonce+0xba>
jmp    115d <gg_oauth_generate_nonce+0x4d>
cmpl   $0x1,-0xc(%rbp)
jle    11c3 <gg_oauth_generate_nonce+0xb3>
xor    %eax,%eax
call   1030 <rand@plt>
cvtss2sd %xmm0,%xmm0
movsd  0xe86(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e63(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe77(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%eax
mov    -0x17(%rbp,%rax,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <gg_oauth_generate_nonce+0x4d>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gg_oauth_generate_nonce>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1181 <gg_oauth_generate_nonce+0x71>
mov    %esi,%ebp
test   %esi,%esi
jle    1181 <gg_oauth_generate_nonce+0x71>
mov    %rdi,%rbx
cmp    $0x2,%ebp
jb     117e <gg_oauth_generate_nonce+0x6e>
add    $0x1,%ebp
mov    0x2eb4(%rip),%r14
lea    0xed5(%rip),%r15
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cvtss2sd %xmm0,%xmm0
mulsd  0xead(%rip),%xmm0
movsd  (%r14),%xmm1
addsd  0xea8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%eax
movzbl (%rax,%r15,1),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
ja     1140 <gg_oauth_generate_nonce+0x30>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.gg_oauth_generate_nonce.charset = [11 x i8] c"0123456789\00"
@RAND_MAX = global double 0.000000e+00
define void @gg_oauth_generate_nonce(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [11 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = bitcast [11 x i8]* %5 to i8*
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %9, %2
br label %34
13: ; preds = %9
br label %14
14: ; preds = %17, %13
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = call float (...) @rand()
%19 = fpext float %18 to double
%20 = fmul double 1.000000e+01, %19
%21 = load double, double* @RAND_MAX
%22 = fadd double %21, 1.000000e+00
%23 = fdiv double %20, %22
%24 = fptoui double %23 to i32
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
store i8 %27, i8* %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, -1
store i32 %31, i32* %4
br label %14
32: ; preds = %14
%33 = load i8*, i8** %3
store i8 0, i8* %33
br label %34
34: ; preds = %32, %12
ret void
}

LLVM IR (-O2):
@__const.gg_oauth_generate_nonce.charset = [11 x i8] c"0123456789\00"
@RAND_MAX = global double 0.000000e+00
define void @gg_oauth_generate_nonce(i8* writeonly %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp slt i32 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = icmp ugt i32 %1, 1
br i1 %7, label %8, label %24
8: ; preds = %6, %8
%9 = phi i32 [ %22, %8 ], [ %1, %6 ]
%10 = phi i8* [ %21, %8 ], [ %0, %6 ]
%11 = tail call float (...) @rand()
%12 = fpext float %11 to double
%13 = fmul double %12, 1.000000e+01
%14 = load double, double* @RAND_MAX
%15 = fadd double %14, 1.000000e+00
%16 = fdiv double %13, %15
%17 = fptoui double %16 to i32
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [11 x i8], [11 x i8]* @__const.gg_oauth_generate_nonce.charset, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %20, i8* %10
%22 = add nsw i32 %9, -1
%23 = icmp ugt i32 %9, 2
br i1 %23, label %8, label %24
24: ; preds = %8, %6
%25 = phi i8* [ %0, %6 ], [ %21, %8 ]
store i8 0, i8* %25
br label %26
26: ; preds = %2, %24
ret void
}