#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, size_t, size_t);
int /*<<< orphan*/ printf(char *, size_t);
int rand();
size_t init_storage_strings(char *storage, size_t storage_size, char **strings,
                            size_t num_strings) {
  char *string = storage;
  for (size_t i = 0; i < num_strings; i++) {
    strings[i] = string + 1;
    size_t string_length = rand() % 32;
    string[0] = (char)string_length + 1;
    string++;
    size_t random_char = (rand() % 255) + 1;
    if (string + string_length < storage + storage_size) {
      memset(string, random_char, string_length);
      string[string_length] = 0;
      string += (string_length + 1);
    } else {
      printf("Strings buffer too small at i = %zd\n", i);
      exit(1);
    }
  }
  size_t storage_bytes_used = string - storage;
  return storage_bytes_used;
}


x86 assembly (clang, -O0):
<init_storage_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1252 <init_storage_strings+0x112>
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x20,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl %al,%eax
add    $0x1,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    1222 <init_storage_strings+0xe2>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    123c <init_storage_strings+0xfc>
mov    -0x30(%rbp),%rsi
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1241 <init_storage_strings+0x101>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1168 <init_storage_strings+0x28>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_storage_strings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rdi,%r14
mov    %rdi,0x8(%rsp)
test   %rcx,%rcx
je     120d <init_storage_strings+0xcd>
mov    %rcx,%r12
mov    %rsi,%r13
mov    0x8(%rsp),%r14
add    %r14,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%r14),%rbp
mov    0x10(%rsp),%rax
mov    %rbp,(%rax,%rbx,8)
xor    %eax,%eax
call   1060 <rand@plt>
lea    0x1f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffe0,%ecx
sub    %ecx,%eax
movslq %eax,%r15
lea    0x1(%r15),%eax
mov    %al,(%r14)
xor    %eax,%eax
call   1060 <rand@plt>
lea    (%r14,%r15,1),%rcx
add    $0x1,%rcx
cmp    %r13,%rcx
jae    1224 <init_storage_strings+0xe4>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
add    %ecx,%eax
add    $0x1,%eax
movslq %eax,%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
call   1040 <memset@plt>
movb   $0x0,0x0(%rbp,%r15,1)
lea    (%r15,%rbp,1),%r14
add    $0x1,%r14
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <init_storage_strings+0x40>
sub    0x8(%rsp),%r14
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Strings buffer too small at i = %zd\0A\00"
define i64 @init_storage_strings(i8* %0, i64 %1, i8** %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
store i64 %3, i64* %8
%14 = load i8*, i8** %5
store i8* %14, i8** %9
store i64 0, i64* %10
br label %15
15: ; preds = %65, %4
%16 = load i64, i64* %10
%17 = load i64, i64* %8
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %68
19: ; preds = %15
%20 = load i8*, i8** %9
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8**, i8*** %7
%23 = load i64, i64* %10
%24 = getelementptr inbounds i8*, i8** %22, i64 %23
store i8* %21, i8** %24
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 32
%27 = sext i32 %26 to i64
store i64 %27, i64* %11
%28 = load i64, i64* %11
%29 = trunc i64 %28 to i8
%30 = sext i8 %29 to i32
%31 = add nsw i32 %30, 1
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %9
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 %32, i8* %34
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %9
%37 = call i32 (...) @rand()
%38 = srem i32 %37, 255
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
store i64 %40, i64* %12
%41 = load i8*, i8** %9
%42 = load i64, i64* %11
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = load i8*, i8** %5
%45 = load i64, i64* %6
%46 = getelementptr inbounds i8, i8* %44, i64 %45
%47 = icmp ult i8* %43, %46
br i1 %47, label %48, label %60
48: ; preds = %19
%49 = load i8*, i8** %9
%50 = load i64, i64* %12
%51 = load i64, i64* %11
%52 = call i32 @memset(i8* %49, i64 %50, i64 %51)
%53 = load i8*, i8** %9
%54 = load i64, i64* %11
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8 0, i8* %55
%56 = load i64, i64* %11
%57 = add i64 %56, 1
%58 = load i8*, i8** %9
%59 = getelementptr inbounds i8, i8* %58, i64 %57
store i8* %59, i8** %9
br label %64
60: ; preds = %19
%61 = load i64, i64* %10
%62 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %48
br label %65
65: ; preds = %64
%66 = load i64, i64* %10
%67 = add i64 %66, 1
store i64 %67, i64* %10
br label %15
68: ; preds = %15
%69 = load i8*, i8** %9
%70 = load i8*, i8** %5
%71 = ptrtoint i8* %69 to i64
%72 = ptrtoint i8* %70 to i64
%73 = sub i64 %71, %72
store i64 %73, i64* %13
%74 = load i64, i64* %13
ret i64 %74
}

LLVM IR (-O2):
@.str = [37 x i8] c"Strings buffer too small at i = %zd\0A\00"
define i64 @init_storage_strings(i8* %0, i64 %1, i8** nocapture writeonly %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %0, i64 %1
br label %13
8: ; preds = %26, %4
%9 = phi i8* [ %0, %4 ], [ %32, %26 ]
%10 = ptrtoint i8* %9 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
ret i64 %12
13: ; preds = %6, %26
%14 = phi i8* [ %0, %6 ], [ %32, %26 ]
%15 = phi i64 [ 0, %6 ], [ %33, %26 ]
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = getelementptr inbounds i8*, i8** %2, i64 %15
store i8* %16, i8** %17
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 32
%20 = sext i32 %19 to i64
%21 = trunc i32 %19 to i8
%22 = add nsw i8 %21, 1
store i8 %22, i8* %14
%23 = tail call i32 (...) @rand()
%24 = getelementptr inbounds i8, i8* %16, i64 %20
%25 = icmp ult i8* %24, %7
br i1 %25, label %26, label %35
26: ; preds = %13
%27 = srem i32 %23, 255
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = tail call i32 @memset(i8* %16, i64 %29, i64 %20)
store i8 0, i8* %24
%31 = add nsw i64 %20, 1
%32 = getelementptr inbounds i8, i8* %16, i64 %31
%33 = add nuw i64 %15, 1
%34 = icmp eq i64 %33, %3
br i1 %34, label %8, label %13
35: ; preds = %13
%36 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %15)
%37 = tail call i32 @exit(i32 1)
unreachable
}