#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*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int random();
int scanf(char *, int *, char *);
int /*<<< orphan*/ srandom(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, const char *argv[]) {
  int length = 10;
  char term;
  int op;
  while (1) {
    printf("Length of the password (1-1024): ");
    op = scanf("%d%c", &length, &term);
    if (op != 2 || term != '\n') {
      printf("Enter numbers only\n");
      return -1;
    }
    if (length < 1 || length > 1024) {
      printf("Please enter a number between 1 and 1024\n");
      continue;
    }
    srandom((unsigned)time(NULL));
    for (; length > 0; length--) {
      putchar(random() % 95 + 32);
    }
    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)
movl   $0xa,-0x14(%rbp)
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x15(%rbp),%rdx
call   1080 <scanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    11b7 <main+0x57>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     11ce <main+0x6e>
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret
cmpl   $0x1,-0x14(%rbp)
jl     11e5 <main+0x85>
cmpl   $0x400,-0x14(%rbp)
jle    11f6 <main+0x96>
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
jmp    117d <main+0x1d>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1237 <main+0xd7>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x5f,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1206 <main+0xa6>
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
jmp    117d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0xa,0x4(%rsp)
lea    0xe76(%rip),%rdi
call   1060 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x3(%rsp),%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    1290 <main+0x120>
cmpb   $0xa,0x3(%rsp)
jne    1290 <main+0x120>
mov    $0xfffffbff,%ebp
lea    0xe62(%rip),%r14
lea    0xe34(%rip),%r15
lea    0xe4f(%rip),%r12
lea    0x4(%rsp),%r13
lea    0x3(%rsp),%rbx
nopl   (%rax)
mov    0x4(%rsp),%eax
add    %ebp,%eax
cmp    $0xfffffbff,%eax
ja     1200 <main+0x90>
mov    %r14,%rdi
call   1050 <puts@plt>
jmp    126a <main+0xfa>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
cmpl   $0x0,0x4(%rsp)
jle    1260 <main+0xf0>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <random@plt>
cltq
imul   $0xffffffffac769185,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x5f,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%edi
add    $0x20,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
cmp    $0x1,%eax
jg     1220 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    1290 <main+0x120>
cmpb   $0xa,0x3(%rsp)
je     11e0 <main+0x70>
lea    0xdb9(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Length of the password (1-1024): \00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [20 x i8] c"Enter numbers only\0A\00"
@.str.3 = [42 x i8] c"Please enter a number between 1 and 1024\0A\00"
@.str.4 = [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
%7 = alloca i8
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
br label %9
9: ; preds = %2, %26, %43
%10 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %7)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 2
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %20
18: ; preds = %14, %9
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
ret i32 -1
20: ; preds = %14
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 1024
br i1 %25, label %26, label %28
26: ; preds = %23, %20
%27 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %9
28: ; preds = %23
%29 = call i64 @time(i32* null)
%30 = trunc i64 %29 to i32
%31 = call i32 @srandom(i32 %30)
br label %32
32: ; preds = %40, %28
%33 = load i32, i32* %6
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = call i32 (...) @random()
%37 = srem i32 %36, 95
%38 = add nsw i32 %37, 32
%39 = call i32 @putchar(i32 %38)
br label %40
40: ; preds = %35
%41 = load i32, i32* %6
%42 = add nsw i32 %41, -1
store i32 %42, i32* %6
br label %32
43: ; preds = %32
%44 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %9
}

LLVM IR (-O2):
@.str = [34 x i8] c"Length of the password (1-1024): \00"
@.str.1 = [5 x i8] c"%d%c\00"
@str = [41 x i8] c"Please enter a number between 1 and 1024\00"
@str.5 = [19 x i8] c"Enter numbers only\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
store i32 10, i32* %3
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%8 = icmp ne i32 %7, 2
%9 = load i8, i8* %4
%10 = icmp ne i8 %9, 10
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %12, label %14
12: ; preds = %20, %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
ret i32 -1
14: ; preds = %2, %20
%15 = load i32, i32* %3
%16 = add i32 %15, -1025
%17 = icmp ult i32 %16, -1024
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %41
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%23 = icmp ne i32 %22, 2
%24 = load i8, i8* %4
%25 = icmp ne i8 %24, 10
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %12, label %14
27: ; preds = %14
%28 = call i64 @time(i32* null)
%29 = trunc i64 %28 to i32
%30 = call i32 @srandom(i32 %29)
%31 = load i32, i32* %3
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %27, %33
%34 = call i32 (...) @random()
%35 = srem i32 %34, 95
%36 = add nsw i32 %35, 32
%37 = call i32 @putchar(i32 %36)
%38 = load i32, i32* %3
%39 = add nsw i32 %38, -1
store i32 %39, i32* %3
%40 = icmp sgt i32 %38, 1
br i1 %40, label %33, label %41
41: ; preds = %33, %27
%42 = call i32 @putchar(i32 10)
br label %20
}