#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(int);
int rand();
char *random_boundary(int len) {
  int i;
  static char *base64 = "0123456789ABCDEFGHIJKLMNOPQRSTU"
                        "VWXYZabcdefghijklmnopqrstuvwxyz+/";
  char *b = malloc(len + 1);
  if (b != NULL) {
    for (i = 0; i < len; i++) {
      int index = rand() % 64;
      b[i] = base64[index];
    }
    b[len] = 0;
  }
  return b;
}


x86 assembly (clang, -O0):
<random_boundary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119d <random_boundary+0x7d>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1191 <random_boundary+0x71>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    0x2ebf(%rip),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114c <random_boundary+0x2c>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_boundary>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1030 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     1182 <random_boundary+0x62>
test   %r14d,%r14d
jle    1179 <random_boundary+0x59>
mov    %r14d,%r15d
lea    0xeb4(%rip),%r12
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r12,1),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <random_boundary+0x30>
movslq %r14d,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@random_boundary.base64 = internal global i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0)
@.str = [65 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/\00"
define i8* @random_boundary(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
%8 = call i8* @malloc(i32 %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %36
11: ; preds = %1
store i32 0, i32* %3
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 64
store i32 %18, i32* %5
%19 = load i8*, i8** @random_boundary.base64
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %16
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %12
31: ; preds = %12
%32 = load i8*, i8** %4
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %31, %1
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
@.str = [65 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/\00"
define noalias i8* @random_boundary(i32 %0) {
%2 = add nsw i32 %0, 1
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp eq i8* %3, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %19
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %17, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 64
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %3, i64 %10
store i8 %15, i8* %16
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %9
19: ; preds = %9, %5
%20 = sext i32 %0 to i64
%21 = getelementptr inbounds i8, i8* %3, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %19, %1
ret i8* %3
}