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

/* Variables and functions */
int /*<<< orphan*/ die(char *);
char *malloc(int);
int pcg32(int /*<<< orphan*/ *);
char *generate(uint64_t *s) {
  int min = 8;
  int max = 300;
  int len = min + pcg32(s) % (max - min);
  char *key = malloc(len + 1);
  if (!key)
    die("out of memory");
  for (int i = 0; i < len; i++)
    key[i] = 1 + pcg32(s) % 255;
  key[len] = 0;
  return key;
}


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x8,-0xc(%rbp)
movl   $0x12c,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <pcg32@plt>
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <generate+0x60>
lea    0xe75(%rip),%rdi
call   1050 <die@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d0 <generate+0xa0>
mov    -0x8(%rbp),%rdi
call   1040 <pcg32@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1197 <generate+0x67>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <pcg32@plt>
cltq
imul   $0xffffffffe070381d,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x8,%ecx
add    %edx,%ecx
imul   $0x124,%ecx,%ecx
mov    %eax,%edx
sub    %ecx,%edx
movslq %edx,%rbx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1188 <generate+0x58>
lea    0xe7d(%rip),%rdi
call   1050 <die@plt>
lea    0x8(%rbx),%r15
cmp    $0xfffffff9,%ebx
jl     11d3 <generate+0xa3>
mov    %r15d,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <pcg32@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
add    $0x1,%cl
mov    %cl,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <generate+0x70>
movb   $0x0,(%r12,%r15,1)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
define i8* @generate(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %2
store i32 8, i32* %3
store i32 300, i32* %4
%8 = load i32, i32* %3
%9 = load i32*, i32** %2
%10 = call i32 @pcg32(i32* %9)
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = sub nsw i32 %11, %12
%14 = srem i32 %10, %13
%15 = add nsw i32 %8, %14
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %1
%22 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %1
store i32 0, i32* %7
br label %24
24: ; preds = %38, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %41
28: ; preds = %24
%29 = load i32*, i32** %2
%30 = call i32 @pcg32(i32* %29)
%31 = srem i32 %30, 255
%32 = add nsw i32 1, %31
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %6
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %28
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %24
41: ; preds = %24
%42 = load i8*, i8** %6
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %6
ret i8* %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
define noalias i8* @generate(i32* %0) {
%2 = tail call i32 @pcg32(i32* %0)
%3 = srem i32 %2, 292
%4 = add nsw i32 %3, 8
%5 = add nsw i32 %3, 9
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = icmp sgt i32 %3, -8
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = zext i32 %4 to i64
br label %17
14: ; preds = %17, %10
%15 = sext i32 %4 to i64
%16 = getelementptr inbounds i8, i8* %6, i64 %15
store i8 0, i8* %16
ret i8* %6
17: ; preds = %12, %17
%18 = phi i64 [ 0, %12 ], [ %24, %17 ]
%19 = tail call i32 @pcg32(i32* %0)
%20 = srem i32 %19, 255
%21 = trunc i32 %20 to i8
%22 = add i8 %21, 1
%23 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 %22, i8* %23
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %13
br i1 %25, label %14, label %17
}