#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();
void random_string_of_len(char *dest, int len) {
  for (int i = 0; i < len - 2; i++) {
    dest[i] = rand() % 256;
  }
  dest[len - 2] = ';';
  dest[len - 1] = '\0';
}


x86 assembly (clang, -O0):
<random_string_of_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    115f <random_string_of_len+0x4f>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <random_string_of_len+0x16>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x3b,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string_of_len>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
lea    -0x2(%r14),%r15d
cmp    $0x3,%esi
jl     1144 <random_string_of_len+0x34>
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1130 <random_string_of_len+0x20>
movslq %r15d,%rax
movb   $0x3b,(%r12,%rax,1)
movslq %r14d,%rax
movb   $0x0,-0x1(%rax,%r12,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @random_string_of_len(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %19, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 2
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 256
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
br label %19
19: ; preds = %11
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %6
22: ; preds = %6
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 59, i8* %27
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 0, i8* %32
ret void
}

LLVM IR (-O2):
define void @random_string_of_len(i8* nocapture writeonly %0, i32 %1) {
%3 = add i32 %1, -2
%4 = icmp sgt i32 %1, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %13
7: ; preds = %13, %2
%8 = sext i32 %3 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 59, i8* %9
%10 = add nsw i32 %1, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
ret void
13: ; preds = %5, %13
%14 = phi i64 [ 0, %5 ], [ %18, %13 ]
%15 = tail call i32 (...) @rand()
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %16, i8* %17
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %7, label %13
}