#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 */
char EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, char);
int random();
int scanf(char *, char *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int sh;
  char c;
  srand(time(NULL));
  sh = (random() % 25) + 1;
  fprintf(stderr, "Generated key: %d\n", sh);
  while (scanf("%c", &c) == 1 && c != EOF) {
    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
      c = (c - (c >= 'a' ? 'a' : 'A') + sh) % 26 + (c >= 'a' ? 'a' : 'A');
    }
    printf("%c", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x19,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe60(%rip),%rdi
lea    -0x9(%rbp),%rsi
call   1080 <scanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0xa(%rbp)
jne    11e2 <main+0x82>
movsbl -0x9(%rbp),%eax
mov    0x2e11(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
test   $0x1,%al
jne    11f2 <main+0x92>
jmp    127b <main+0x11b>
movsbl -0x9(%rbp),%eax
cmp    $0x61,%eax
jl     120c <main+0xac>
movsbl -0x9(%rbp),%eax
cmp    $0x7a,%eax
jle    1226 <main+0xc6>
movsbl -0x9(%rbp),%eax
cmp    $0x41,%eax
jl     1266 <main+0x106>
movsbl -0x9(%rbp),%eax
cmp    $0x5a,%eax
jg     1266 <main+0x106>
movsbl -0x9(%rbp),%eax
movsbl -0x9(%rbp),%esi
mov    $0x41,%ecx
mov    $0x61,%edx
cmp    $0x61,%esi
cmovge %edx,%ecx
sub    %ecx,%eax
add    -0x8(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
movsbl -0x9(%rbp),%esi
mov    $0x41,%eax
mov    $0x61,%ecx
cmp    $0x61,%esi
cmovge %ecx,%eax
add    %eax,%edx
mov    %dl,%al
mov    %al,-0x9(%rbp)
lea    0xda6(%rip),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <printf@plt>
jmp    11ac <main+0x4c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <random@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r14d
add    $0x1,%r14d
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    %r14d,%edx
call   1050 <fprintf@plt>
lea    0xe52(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    1279 <main+0x119>
mov    0x7(%rsp),%al
mov    0x2e09(%rip),%r15
cmp    (%r15),%al
je     1279 <main+0x119>
lea    0xe24(%rip),%rbx
lea    0x7(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ecx
and    $0xdf,%cl
add    $0xbf,%cl
cmp    $0x19,%cl
ja     1254 <main+0xf4>
movzbl %al,%edx
xor    %ecx,%ecx
xor    %esi,%esi
cmp    $0x61,%al
setae  %cl
setb   %sil
shl    $0x5,%esi
shl    $0x5,%ecx
add    %r14d,%edx
lea    (%rsi,%rdx,1),%eax
add    $0xffffff9f,%eax
cltq
imul   $0x4ec4ec4f,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x23,%rdx
add    %esi,%edx
lea    (%rdx,%rdx,4),%esi
lea    (%rsi,%rsi,4),%esi
add    %edx,%esi
sub    %esi,%eax
add    %ecx,%eax
add    $0x41,%al
mov    %al,0x7(%rsp)
movsbl %al,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    1279 <main+0x119>
movzbl 0x7(%rsp),%eax
cmp    (%r15),%al
jne    1200 <main+0xa0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Generated key: %d\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 @time(i32* null)
%5 = call i32 @srand(i32 %4)
%6 = call i32 (...) @random()
%7 = srem i32 %6, 25
%8 = add nsw i32 %7, 1
store i32 %8, i32* %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %58, %0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br label %21
21: ; preds = %15, %12
%22 = phi i1 [ false, %12 ], [ %20, %15 ]
br i1 %22, label %23, label %61
23: ; preds = %21
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp sge i32 %25, 97
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp sle i32 %29, 122
br i1 %30, label %39, label %31
31: ; preds = %27, %23
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp sge i32 %33, 65
br i1 %34, label %35, label %58
35: ; preds = %31
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = icmp sle i32 %37, 90
br i1 %38, label %39, label %58
39: ; preds = %35, %27
%40 = load i8, i8* %3
%41 = sext i8 %40 to i32
%42 = load i8, i8* %3
%43 = sext i8 %42 to i32
%44 = icmp sge i32 %43, 97
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 97, i32 65
%47 = sub nsw i32 %41, %46
%48 = load i32, i32* %2
%49 = add nsw i32 %47, %48
%50 = srem i32 %49, 26
%51 = load i8, i8* %3
%52 = sext i8 %51 to i32
%53 = icmp sge i32 %52, 97
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 97, i32 65
%56 = add nsw i32 %50, %55
%57 = trunc i32 %56 to i8
store i8 %57, i8* %3
br label %58
58: ; preds = %39, %35, %31
%59 = load i8, i8* %3
%60 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %59)
br label %12
61: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Generated key: %d\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (...) @random()
%5 = srem i32 %4, 25
%6 = add nsw i32 %5, 1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = icmp eq i32 %9, 1
%11 = load i8, i8* %1
%12 = load i8, i8* @EOF
%13 = icmp ne i8 %11, %12
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %15, label %39
15: ; preds = %0, %30
%16 = phi i8 [ %35, %30 ], [ %11, %0 ]
%17 = and i8 %16, -33
%18 = add i8 %17, -65
%19 = icmp ult i8 %18, 26
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = zext i8 %16 to i32
%22 = icmp ugt i8 %16, 96
%23 = select i1 %22, i32 -97, i32 -65
%24 = select i1 %22, i32 97, i32 65
%25 = add nsw i32 %6, %21
%26 = add nsw i32 %25, %23
%27 = srem i32 %26, 26
%28 = add nsw i32 %27, %24
%29 = trunc i32 %28 to i8
store i8 %29, i8* %1
br label %30
30: ; preds = %15, %20
%31 = phi i8 [ %16, %15 ], [ %29, %20 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %31)
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%34 = icmp eq i32 %33, 1
%35 = load i8, i8* %1
%36 = load i8, i8* @EOF
%37 = icmp ne i8 %35, %36
%38 = select i1 %34, i1 %37, i1 false
br i1 %38, label %15, label %39
39: ; preds = %30, %0
ret i32 0
}