#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int randChar();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("USAGE: keygen keylength\n");
    return 1;
  } else {
    srand((unsigned int)time(NULL));
    int i;
    for (i = 0; i < atoi(argv[1]); i++)
      printf("%c", randChar());
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1200 <main+0xb0>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11e6 <main+0x96>
mov    $0x0,%al
call   1060 <randChar@plt>
mov    %eax,%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <main+0x51>
jmp    11eb <main+0x9b>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     117d <main+0x1d>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
jmp    11c8 <main+0x68>
mov    %rsi,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    11be <main+0x5e>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <randChar@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
cmp    %eax,%ebp
jl     11a0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"USAGE: keygen keylength\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %31
11: ; preds = %2
%12 = call i64 @time(i32* null)
%13 = trunc i64 %12 to i32
%14 = call i32 @srand(i32 %13)
store i32 0, i32* %6
br label %15
15: ; preds = %25, %11
%16 = load i32, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
%21 = icmp slt i32 %16, %20
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = call i32 (...) @randChar()
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %15
28: ; preds = %15
br label %29
29: ; preds = %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %31
31: ; preds = %29, %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@str = [24 x i8] c"USAGE: keygen keylength\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %24
6: ; preds = %2
%7 = tail call i64 @time(i32* null)
%8 = trunc i64 %7 to i32
%9 = tail call i32 @srand(i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %6, %14
%15 = phi i32 [ %18, %14 ], [ 0, %6 ]
%16 = tail call i32 (...) @randChar()
%17 = tail call i32 @putchar(i32 %16)
%18 = add nuw nsw i32 %15, 1
%19 = load i8*, i8** %10
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp slt i32 %18, %20
br i1 %21, label %14, label %22
22: ; preds = %14, %6
%23 = tail call i32 @putchar(i32 10)
br label %24
24: ; preds = %22, %4
%25 = phi i32 [ 1, %4 ], [ 0, %22 ]
ret i32 %25
}