#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 */
struct vehicle {
  int dummy;
};

/* Variables and functions */
char *malloc(int /*<<< orphan*/);
struct vehicle *mkvehicle(int, char *);
int rand();
struct vehicle *rand_vehicle() {
  int len = rand() % 42 + 2;
  char *name = malloc(len--);
  for (int j = 0; j < len; ++j)
    name[j] = 'a' + rand() % 26;
  name[len] = 0;
  return mkvehicle(rand() % 5, name);
}


x86 assembly (clang, -O0):
<rand_vehicle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x2a,%ecx
cltd
idiv   %ecx
add    $0x2,%edx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119f <rand_vehicle+0x6f>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <rand_vehicle+0x38>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x10(%rbp),%rsi
call   1040 <mkvehicle@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_vehicle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x30c30c31,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
imul   $0x2a,%ecx,%ecx
mov    %eax,%ebx
sub    %ecx,%ebx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
movslq %ebx,%rax
lea    0x1(%rax),%r14
test   %eax,%eax
js     11b6 <rand_vehicle+0x86>
mov    %r14d,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x61,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <rand_vehicle+0x50>
movb   $0x0,(%r15,%r14,1)
xor    %eax,%eax
call   1050 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <mkvehicle@plt>

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

LLVM IR (-O2):
%struct.vehicle = type { i32 }
define %struct.vehicle* @rand_vehicle() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 42
%3 = add nsw i32 %2, 2
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp slt i32 %2, 0
%6 = add nsw i32 %2, 1
br i1 %5, label %9, label %7
7: ; preds = %0
%8 = zext i32 %6 to i64
br label %15
9: ; preds = %15, %0
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds i8, i8* %4, i64 %10
store i8 0, i8* %11
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 5
%14 = tail call %struct.vehicle* @mkvehicle(i32 %13, i8* %4)
ret %struct.vehicle* %14
15: ; preds = %7, %15
%16 = phi i64 [ 0, %7 ], [ %22, %15 ]
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 26
%19 = trunc i32 %18 to i8
%20 = add nsw i8 %19, 97
%21 = getelementptr inbounds i8, i8* %4, i64 %16
store i8 %20, i8* %21
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %9, label %15
}