#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*/ fixbag(char *, int *);
int /*<<< orphan*/ printf(char *, char *);
int random();
int sublbag(int *, char);
void randomrack(char *bufrack, int *bag, int size) {
  char letter;
  int i;
  for (i = 0; i < size; i++) {
    letter = (random() % 27) + 65;
    if (sublbag(bag, letter) == -1) {
      fixbag(bufrack, bag);
      randomrack(bufrack, bag, size);
    }
    bufrack[i] = letter;
  }
  bufrack[size] = '\0';
  printf("rack = %s\n", bufrack);
}


x86 assembly (clang, -O0):
<randomrack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11dc <randomrack+0x8c>
mov    $0x0,%al
call   1040 <random@plt>
mov    $0x1b,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1070 <sublbag@plt>
cmp    $0xffffffff,%eax
jne    11c0 <randomrack+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fixbag@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <randomrack@plt>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <randomrack+0x1a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomrack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rdi,%r13
test   %edx,%edx
jle    11d2 <randomrack+0x82>
mov    %rsi,%r12
mov    %r14d,%r15d
xor    %ebp,%ebp
jmp    117e <randomrack+0x2e>
nop
mov    %bl,0x0(%r13,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11d2 <randomrack+0x82>
xor    %eax,%eax
call   1040 <random@plt>
movslq %eax,%rbx
imul   $0x4bda12f7,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,8),%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
add    $0x41,%bl
movsbl %bl,%esi
mov    %r12,%rdi
call   1070 <sublbag@plt>
cmp    $0xffffffff,%eax
jne    1170 <randomrack+0x20>
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <fixbag@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1050 <randomrack@plt>
jmp    1170 <randomrack+0x20>
movslq %r14d,%rax
movb   $0x0,0x0(%r13,%rax,1)
lea    0xe1e(%rip),%rdi
mov    %r13,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"rack = %s\0A\00"
define void @randomrack(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %35, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %9
%14 = call i32 (...) @random()
%15 = srem i32 %14, 27
%16 = add nsw i32 %15, 65
%17 = trunc i32 %16 to i8
store i8 %17, i8* %7
%18 = load i32*, i32** %5
%19 = load i8, i8* %7
%20 = call i32 @sublbag(i32* %18, i8 signext %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %29
22: ; preds = %13
%23 = load i8*, i8** %4
%24 = load i32*, i32** %5
%25 = call i32 @fixbag(i8* %23, i32* %24)
%26 = load i8*, i8** %4
%27 = load i32*, i32** %5
%28 = load i32, i32* %6
br label %29
29: ; preds = %22, %13
%30 = load i8, i8* %7
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %29
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %9
38: ; preds = %9
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %4
%44 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"rack = %s\0A\00"
define void @randomrack(i8* %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %21
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %17
%8 = phi i64 [ 0, %5 ], [ %19, %17 ]
%9 = tail call i32 (...) @random()
%10 = srem i32 %9, 27
%11 = trunc i32 %10 to i8
%12 = add nsw i8 %11, 65
%13 = tail call i32 @sublbag(i32* %1, i8 signext %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @fixbag(i8* %0, i32* %1)
tail call void @randomrack(i8* %0, i32* %1, i32 %2)
br label %17
17: ; preds = %15, %7
%18 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %12, i8* %18
%19 = add nuw nsw i64 %8, 1
%20 = icmp eq i64 %19, %6
br i1 %20, label %21, label %7
21: ; preds = %17, %3
%22 = sext i32 %2 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
%24 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
ret void
}