#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 rand();
void genpass(char *b, size_t n) {
  size_t i;
  if (n == 0)
    return;
  for (i = 0; i < n - 1; i++)
    b[i] = 32 + (rand() % 95);
  b[i] = '\0';
}


x86 assembly (clang, -O0):
<genpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1130 <genpass+0x20>
jmp    1187 <genpass+0x77>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    117b <genpass+0x6b>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x5f,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <genpass+0x28>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genpass>:
test   %rsi,%rsi
je     116e <genpass+0x5e>
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
add    $0xffffffffffffffff,%r15
je     1164 <genpass+0x54>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffffac769185,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x6,%ecx
add    %edx,%ecx
imul   $0x5f,%ecx,%ecx
sub    %ecx,%eax
add    $0x20,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <genpass+0x20>
movb   $0x0,(%r14,%r15,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @genpass(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %30
9: ; preds = %2
store i64 0, i64* %5
br label %10
10: ; preds = %23, %9
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = sub i64 %12, 1
%14 = icmp ult i64 %11, %13
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 95
%18 = add nsw i32 32, %17
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %3
%21 = load i64, i64* %5
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 %19, i8* %22
br label %23
23: ; preds = %15
%24 = load i64, i64* %5
%25 = add i64 %24, 1
store i64 %25, i64* %5
br label %10
26: ; preds = %10
%27 = load i8*, i8** %3
%28 = load i64, i64* %5
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %26, %8
ret void
}

LLVM IR (-O2):
define void @genpass(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = add i64 %1, -1
%6 = icmp eq i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %4, %7
%8 = phi i64 [ %14, %7 ], [ 0, %4 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 95
%11 = trunc i32 %10 to i8
%12 = add nsw i8 %11, 32
%13 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %12, i8* %13
%14 = add nuw i64 %8, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %7
16: ; preds = %7, %4
%17 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 0, i8* %17
br label %18
18: ; preds = %2, %16
ret void
}