#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 */
size_t next_range(int const);
int /*<<< orphan*/ printf(char *, char *);
void test_random(void) {
  const int size = 53;
  char buffer[size];
  int ib = 0;
  int i = 65;
  for (; i < 91; i++)
    buffer[ib++] = (char)i;
  for (i = 97; i < 123; i++)
    buffer[ib++] = (char)i;
  buffer[ib] = '\0';
  printf("Buffer: %s\n", buffer);
  char key[20];
  for (i = 0; i < 20; i++) {
    if (i % 5 == 0 && i != 0)
      key[i] = '-';
    else
      key[i] = buffer[next_range(size)];
  }
  key[i] = '\0';
  printf("Key: %s\n", key);
}


x86 assembly (clang, -O0):
<test_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x35,-0x4(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x41,-0x18(%rbp)
cmpl   $0x5b,-0x18(%rbp)
jge    1172 <test_random+0x52>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1144 <test_random+0x24>
movl   $0x61,-0x18(%rbp)
cmpl   $0x7b,-0x18(%rbp)
jge    11a7 <test_random+0x87>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1179 <test_random+0x59>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    0xe49(%rip),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x14,-0x18(%rbp)
jge    1226 <test_random+0x106>
mov    -0x18(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fd <test_random+0xdd>
cmpl   $0x0,-0x18(%rbp)
je     11fd <test_random+0xdd>
movslq -0x18(%rbp),%rax
movb   $0x2d,-0x30(%rbp,%rax,1)
jmp    1213 <test_random+0xf3>
mov    $0x35,%edi
call   1040 <next_range@plt>
mov    -0x70(%rbp,%rax,1),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    1218 <test_random+0xf8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c7 <test_random+0xa7>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_random>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeda(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movl   $0x7a797877,0x50(%rsp)
7a
movb   $0x0,0x54(%rsp)
lea    0xed1(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1030 <printf@plt>
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1190 <test_random+0x70>
mov    $0x35,%edi
call   1040 <next_range@plt>
movzbl 0x20(%rsp,%rax,1),%eax
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
add    $0xff,%r14b
cmp    $0x14,%rbx
je     11ad <test_random+0x8d>
test   %rbx,%rbx
je     1170 <test_random+0x50>
movzbl %bl,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
lea    (%rax,%rax,4),%ecx
mov    $0x2d,%al
add    %r14b,%cl
je     117f <test_random+0x5f>
jmp    1170 <test_random+0x50>
movb   $0x0,0x14(%rsp)
lea    0xe83(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Buffer: %s\0A\00"
@.str.1 = [9 x i8] c"Key: %s\0A\00"
define void @test_random() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i8]
store i32 53, i32* %1
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %2
%7 = alloca i8, i64 53
store i32 0, i32* %3
store i32 65, i32* %4
br label %8
8: ; preds = %18, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 91
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i32, i32* %4
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %7, i64 %16
store i8 %13, i8* %17
br label %18
18: ; preds = %11
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %8
21: ; preds = %8
store i32 97, i32* %4
br label %22
22: ; preds = %32, %21
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 123
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %4
%27 = trunc i32 %26 to i8
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %7, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %25
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %22
35: ; preds = %22
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %7, i64 %37
store i8 0, i8* %38
%39 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %7)
store i32 0, i32* %4
br label %40
40: ; preds = %62, %35
%41 = load i32, i32* %4
%42 = icmp slt i32 %41, 20
br i1 %42, label %43, label %65
43: ; preds = %40
%44 = load i32, i32* %4
%45 = srem i32 %44, 5
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %43
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %52
store i8 45, i8* %53
br label %61
54: ; preds = %47, %43
%55 = call i64 @next_range(i32 53)
%56 = getelementptr inbounds i8, i8* %7, i64 %55
%57 = load i8, i8* %56
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %59
store i8 %57, i8* %60
br label %61
61: ; preds = %54, %50
br label %62
62: ; preds = %61
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
br label %40
65: ; preds = %40
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %67
store i8 0, i8* %68
%69 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%70 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %69)
%71 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Buffer: %s\0A\00"
@.str.1 = [9 x i8] c"Key: %s\0A\00"
define void @test_random() {
%1 = alloca [20 x i8]
%2 = alloca [53 x i8]
%3 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 0
%4 = bitcast [53 x i8]* %2 to <16 x i8>*
store <16 x i8> <i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79, i8 80>, <16 x i8>* %4
%5 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 16
%6 = bitcast i8* %5 to <16 x i8>*
store <16 x i8> <i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 97, i8 98, i8 99, i8 100, i8 101, i8 102>, <16 x i8>* %6
%7 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 32
%8 = bitcast i8* %7 to <16 x i8>*
store <16 x i8> <i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112, i8 113, i8 114, i8 115, i8 116, i8 117, i8 118>, <16 x i8>* %8
%9 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 48
store i8 119, i8* %9
%10 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 49
store i8 120, i8* %10
%11 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 50
store i8 121, i8* %11
%12 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 51
store i8 122, i8* %12
%13 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 52
store i8 0, i8* %13
%14 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %3)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
br label %16
16: ; preds = %0, %27
%17 = phi i64 [ 0, %0 ], [ %30, %27 ]
%18 = trunc i64 %17 to i8
%19 = urem i8 %18, 5
%20 = icmp eq i8 %19, 0
%21 = icmp ne i64 %17, 0
%22 = and i1 %21, %20
br i1 %22, label %27, label %23
23: ; preds = %16
%24 = call i64 @next_range(i32 53)
%25 = getelementptr inbounds [53 x i8], [53 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
br label %27
27: ; preds = %16, %23
%28 = phi i8 [ %26, %23 ], [ 45, %16 ]
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %17
store i8 %28, i8* %29
%30 = add nuw nsw i64 %17, 1
%31 = icmp eq i64 %30, 20
br i1 %31, label %32, label %16
32: ; preds = %27
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 20
store i8 0, i8* %33
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %15)
ret void
}