#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 */
char createChar(int);
scalar_t__ mymalloc(unsigned long);
int /*<<< orphan*/ srand(int);
char *init(unsigned long int sz, int ratio) {
  int i = 0;
  char *text = (char *)mymalloc(sz + 1);
  srand(1);
  for (i = 0; i < sz; i++) {
    char c = createChar(ratio);
    text[i] = c;
  }
  text[i] = '\0';
  return text;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
call   1030 <srand@plt>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    119d <init+0x6d>
mov    -0xc(%rbp),%edi
call   1050 <createChar@plt>
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <init+0x38>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
add    $0x1,%rdi
call   1040 <mymalloc@plt>
mov    %rax,%r14
mov    $0x1,%edi
call   1030 <srand@plt>
test   %rbx,%rbx
je     1179 <init+0x49>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1050 <createChar@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <init+0x30>
mov    %ebx,%eax
jmp    117b <init+0x4b>
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @init(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i64 %0, i64* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i64, i64* %3
%9 = add i64 %8, 1
%10 = call i64 @mymalloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = call i32 @srand(i32 1)
store i32 0, i32* %5
br label %13
13: ; preds = %26, %2
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = load i64, i64* %3
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %13
%19 = load i32, i32* %4
%20 = call signext i8 @createChar(i32 %19)
store i8 %20, i8* %7
%21 = load i8, i8* %7
%22 = load i8*, i8** %6
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %18
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %13
29: ; preds = %13
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %6
ret i8* %34
}

LLVM IR (-O2):
define i8* @init(i64 %0, i32 %1) {
%3 = add i64 %0, 1
%4 = tail call i64 @mymalloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @srand(i32 1)
%7 = icmp eq i64 %0, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %8
%9 = phi i64 [ %12, %8 ], [ 0, %2 ]
%10 = tail call signext i8 @createChar(i32 %1)
%11 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %10, i8* %11
%12 = add nuw i64 %9, 1
%13 = icmp eq i64 %12, %0
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = and i64 %0, 4294967295
br label %16
16: ; preds = %14, %2
%17 = phi i64 [ 0, %2 ], [ %15, %14 ]
%18 = getelementptr inbounds i8, i8* %5, i64 %17
store i8 0, i8* %18
ret i8* %5
}