#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();
char *test_string(void) {
  static char text[0x101];
  int length = (rand() & 0xff) + 1;
  text[length] = '\0';
  while (length--) {
    text[length] = (rand() % (128 - ' ')) + ' ';
  }
  return text;
}


x86 assembly (clang, -O0):
<test_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <rand@plt>
and    $0xff,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2f0b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     1172 <test_string+0x62>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x60,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
movslq -0x4(%rbp),%rcx
lea    0x2ed6(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1139 <test_string+0x29>
lea    0x2ec7(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_string>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
movzbl %al,%ecx
lea    0x2f1b(%rip),%r14
movb   $0x0,0x1(%rcx,%r14,1)
movzbl %al,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x24,%rcx
add    %edx,%ecx
shl    $0x5,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
add    $0x20,%al
mov    %al,(%rbx,%r14,1)
add    $0xffffffffffffffff,%rbx
jb     1130 <test_string+0x20>
lea    0x2ed8(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@test_string.text = internal global [257 x i8] zeroinitializer
define i8* @test_string() {
%1 = alloca i32
%2 = call i32 (...) @rand()
%3 = and i32 %2, 255
%4 = add nsw i32 %3, 1
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [257 x i8], [257 x i8]* @test_string.text, i64 0, i64 %6
store i8 0, i8* %7
br label %8
8: ; preds = %12, %0
%9 = load i32, i32* %1
%10 = add nsw i32 %9, -1
store i32 %10, i32* %1
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 96
%15 = add nsw i32 %14, 32
%16 = trunc i32 %15 to i8
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [257 x i8], [257 x i8]* @test_string.text, i64 0, i64 %18
store i8 %16, i8* %19
br label %8
20: ; preds = %8
ret i8* getelementptr inbounds ([257 x i8], [257 x i8]* @test_string.text, i64 0, i64 0)
}

LLVM IR (-O2):
@test_string.text = internal global [257 x i8] zeroinitializer
define i8* @test_string() {
%1 = tail call i32 (...) @rand()
%2 = and i32 %1, 255
%3 = add nuw nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [257 x i8], [257 x i8]* @test_string.text, i64 0, i64 %4
store i8 0, i8* %5
%6 = and i32 %1, 255
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %0, %8
%9 = phi i64 [ %7, %0 ], [ %15, %8 ]
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 96
%12 = trunc i32 %11 to i8
%13 = add nsw i8 %12, 32
%14 = getelementptr inbounds [257 x i8], [257 x i8]* @test_string.text, i64 0, i64 %9
store i8 %13, i8* %14
%15 = add nsw i64 %9, -1
%16 = icmp eq i64 %9, 0
br i1 %16, label %17, label %8
17: ; preds = %8
ret i8* getelementptr inbounds ([257 x i8], [257 x i8]* @test_string.text, i64 0, i64 0)
}