#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 *malloc(size_t);
char ranchr();
int /*<<< orphan*/ utest_init_RNG();
char *utest_ran_string(size_t size) {
  int i, r;
  char *str;
  if (size < 1)
    return NULL;
  str = malloc(size + 1);
  if (str == NULL)
    return NULL;
  utest_init_RNG();
  for (i = 0; i < size; i++)
    str[i] = ranchr();
  str[i] = 0;
  return str;
}


x86 assembly (clang, -O0):
<utest_ran_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jae    1154 <utest_ran_string+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11cf <utest_ran_string+0x9f>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117d <utest_ran_string+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11cf <utest_ran_string+0x9f>
mov    $0x0,%al
call   1030 <utest_init_RNG@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11bb <utest_ran_string+0x8b>
mov    $0x0,%al
call   1040 <ranchr@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <utest_ran_string+0x5b>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utest_ran_string>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     117e <utest_ran_string+0x4e>
mov    %rdi,%r15
add    $0x1,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     117e <utest_ran_string+0x4e>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <utest_init_RNG@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <ranchr@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <utest_ran_string+0x30>
mov    %r15d,%eax
movb   $0x0,(%r14,%rax,1)
jmp    1181 <utest_ran_string+0x51>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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