#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncpy(char *, char *, int);
long strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usage(char *);
main(int argc, char **argv) {
  long int keyLength;
  long int i;
  char k;
  char *keyArray = (char *)malloc(27 * sizeof(char));
  strncpy(keyArray, "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", 27);
  if (argc < 2) {
    fprintf(stderr, "ERROR: Missing argument\n");
    usage(argv[0]);
    exit(1);
  }
  keyLength = strtol(argv[1], NULL, 10);
  if (keyLength <= 0) {
    fprintf(stderr, "ERROR: Couldn't interpret %s as a positive integer\n",
            argv[1]);
    usage(argv[0]);
    exit(1);
  }
  srand(time(NULL));
  for (i = 0; i < keyLength; i++) {
    k = keyArray[rand() % 27];
    putc(k, stdout);
  }
  putc('\n', stdout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1b,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x1b,%edx
call   1030 <strncpy@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1210 <main+0x70>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jg     126a <main+0xca>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    12d9 <main+0x139>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x1b,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
mov    0x2d1a(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1282 <main+0xe2>
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0x1b,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    0xe42(%rip),%rsi
mov    %rax,%rdi
mov    $0x1b,%edx
call   1030 <strncpy@plt>
cmp    $0x1,%ebx
jle    125f <main+0xbf>
mov    0x8(%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
test   %rax,%rax
jle    1278 <main+0xd8>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    0x2dd3(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x4bda12f7,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,8),%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cltq
movsbl (%r15,%rax,1),%edi
mov    (%r14),%esi
call   1050 <putc@plt>
add    $0xffffffffffffffff,%rbx
jne    1210 <main+0x70>
mov    (%r14),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1293 <main+0xf3>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xda9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%rdi
call   10a0 <usage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ \00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"ERROR: Missing argument\0A\00"
@.str.2 = [52 x i8] c"ERROR: Couldn't interpret %s as a positive integer\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @malloc(i32 27)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = call i32 @strncpy(i8* %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 27)
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @usage(i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strtol(i8* %27, i32* null, i32 10)
store i64 %28, i64* %6
%29 = load i64, i64* %6
%30 = icmp sle i64 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @usage(i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %24
%43 = call i32 @time(i32* null)
%44 = call i32 @srand(i32 %43)
store i64 0, i64* %7
br label %45
45: ; preds = %59, %42
%46 = load i64, i64* %7
%47 = load i64, i64* %6
%48 = icmp slt i64 %46, %47
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = load i8*, i8** %9
%51 = call i32 (...) @rand()
%52 = srem i32 %51, 27
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %50, i64 %53
%55 = load i8, i8* %54
store i8 %55, i8* %8
%56 = load i8, i8* %8
%57 = load i32, i32* @stdout
%58 = call i32 @putc(i8 signext %56, i32 %57)
br label %59
59: ; preds = %49
%60 = load i64, i64* %7
%61 = add nsw i64 %60, 1
store i64 %61, i64* %7
br label %45
62: ; preds = %45
%63 = load i32, i32* @stdout
%64 = call i32 @putc(i8 signext 10, i32 %63)
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [28 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ \00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"ERROR: Missing argument\0A\00"
@.str.2 = [52 x i8] c"ERROR: Couldn't interpret %s as a positive integer\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 @malloc(i32 27)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 27)
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8*, i8** %1
%11 = tail call i32 @usage(i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @strtol(i8* nocapture %15, i32* null, i32 10)
%17 = icmp slt i64 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %14
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %1
%23 = tail call i32 @usage(i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %13
%26 = tail call i32 @time(i32* null)
%27 = tail call i32 @srand(i32 %26)
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ %37, %28 ], [ 0, %25 ]
%30 = tail call i32 (...) @rand()
%31 = srem i32 %30, 27
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %4, i64 %32
%34 = load i8, i8* %33
%35 = load i32, i32* @stdout
%36 = tail call i32 @putc(i8 signext %34, i32 %35)
%37 = add nuw nsw i64 %29, 1
%38 = icmp eq i64 %37, %16
br i1 %38, label %39, label %28
39: ; preds = %28
%40 = load i32, i32* @stdout
%41 = tail call i32 @putc(i8 signext 10, i32 %40)
ret i32 0
}