#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*/ encrypt(char *, int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
char optopt;
int parsekey(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int key;
  int c;
  char msg[80];
  opterr = 0;
  while ((c = getopt(argc, argv, "k:f:")) != -1) {
    switch (c) {
    case 'k':
      key = strtol(optarg, NULL, 0);
      break;
    case 'f':
      key = parsekey(optarg);
      break;
    case '?':
      if (optopt == 'k')
        fprintf(stderr, "Option -%c requires an argument.\n", optopt);
      else if (isprint(optopt))
        fprintf(stderr, "Unknown option '-%c'.\n", optopt);
      else
        fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
      return 1;
    default:
      break;
    }
  }
  while (fgets(msg, 80, stdin)) {
    encrypt(msg, key);
    printf("%s", msg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e20(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     12db <main+0x15b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0x3f,%eax
je     122e <main+0xae>
jmp    11da <main+0x5a>
mov    -0x74(%rbp),%eax
sub    $0x66,%eax
je     1218 <main+0x98>
jmp    11eb <main+0x6b>
mov    -0x74(%rbp),%eax
sub    $0x6b,%eax
jne    12d1 <main+0x151>
jmp    11fc <main+0x7c>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    12d6 <main+0x156>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1030 <parsekey@plt>
mov    %eax,-0x14(%rbp)
jmp    12d6 <main+0x156>
mov    0x2da3(%rip),%rax
movsbl (%rax),%eax
cmp    $0x6b,%eax
jne    1265 <main+0xe5>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    0x2d80(%rip),%rax
movsbl (%rax),%edx
call   1070 <fprintf@plt>
jmp    12c5 <main+0x145>
mov    0x2d6c(%rip),%rax
movsbl (%rax),%edi
call   1090 <isprint@plt>
cmp    $0x0,%eax
je     12a1 <main+0x121>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    0x2d44(%rip),%rax
movsbl (%rax),%edx
call   1070 <fprintf@plt>
jmp    12c0 <main+0x140>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
mov    0x2d20(%rip),%rax
movsbl (%rax),%edx
call   1070 <fprintf@plt>
jmp    12c5 <main+0x145>
movl   $0x1,-0x4(%rbp)
jmp    1329 <main+0x1a9>
jmp    12d6 <main+0x156>
jmp    11a7 <main+0x27>
jmp    12e0 <main+0x160>
lea    -0x70(%rbp),%rdi
mov    0x2cf5(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1322 <main+0x1a2>
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <encrypt@plt>
lea    -0x70(%rbp),%rsi
lea    0xd48(%rip),%rdi
call   1040 <printf@plt>
jmp    12e0 <main+0x160>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e28(%rip),%rax
movq   $0x0,(%rax)
lea    0xe5a(%rip),%r15
mov    0x2e4b(%rip),%r12
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0x65,%eax
jg     11e0 <main+0x60>
cmp    $0xffffffff,%eax
je     120a <main+0x8a>
cmp    $0x3f,%eax
jne    11b0 <main+0x30>
jmp    126e <main+0xee>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x66,%eax
je     11fc <main+0x7c>
cmp    $0x6b,%eax
jne    11b0 <main+0x30>
mov    (%r12),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,%r14d
jmp    11b0 <main+0x30>
mov    (%r12),%edi
call   1030 <parsekey@plt>
mov    %eax,%r14d
jmp    11b0 <main+0x30>
mov    0x2dcf(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     12c7 <main+0x147>
mov    %rsp,%rbp
lea    0xe28(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <encrypt@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbp,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    1240 <main+0xc0>
jmp    12c7 <main+0x147>
mov    0x2d63(%rip),%rbx
mov    (%rbx),%al
cmp    $0x6b,%al
jne    1292 <main+0x112>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
mov    $0x6b,%edx
jmp    12bc <main+0x13c>
movsbl %al,%edi
call   1090 <isprint@plt>
mov    0x2d27(%rip),%rcx
mov    (%rcx),%edi
mov    (%rbx),%cl
movsbl %cl,%edx
test   %eax,%eax
je     12b5 <main+0x135>
lea    0xd74(%rip),%rsi
jmp    12bc <main+0x13c>
lea    0xd82(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@opterr = global i64 0
@.str = [5 x i8] c"k:f:\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Option -%c requires an argument.\0A\00"
@.str.2 = [23 x i8] c"Unknown option '-%c'.\0A\00"
@.str.3 = [34 x i8] c"Unknown option character '\\x%x'.\0A\00"
@stdin = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @opterr
br label %9
9: ; preds = %45, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %46
14: ; preds = %9
%15 = load i32, i32* %7
switch i32 %15, label %44 [
i32 107, label %16
i32 102, label %19
i32 63, label %22
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = call i32 @strtol(i32 %17, i32* null, i32 0)
store i32 %18, i32* %6
br label %45
19: ; preds = %14
%20 = load i32, i32* @optarg
%21 = call i32 @parsekey(i32 %20)
store i32 %21, i32* %6
br label %45
22: ; preds = %14
%23 = load i8, i8* @optopt
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 107
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8, i8* @optopt
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8 signext %28)
br label %43
30: ; preds = %22
%31 = load i8, i8* @optopt
%32 = call i32 @isprint(i8 signext %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load i8, i8* @optopt
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %36)
br label %42
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = load i8, i8* @optopt
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8 signext %40)
br label %42
42: ; preds = %38, %34
br label %43
43: ; preds = %42, %26
store i32 1, i32* %3
br label %59
44: ; preds = %14
br label %45
45: ; preds = %44, %19, %16
br label %9
46: ; preds = %9
br label %47
47: ; preds = %52, %46
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%49 = load i32, i32* @stdin
%50 = call i64 @fgets(i8* %48, i32 80, i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%54 = load i32, i32* %6
%55 = call i32 @encrypt(i8* %53, i32 %54)
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%57 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %56)
br label %47
58: ; preds = %47
store i32 0, i32* %3
br label %59
59: ; preds = %58, %43
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [5 x i8] c"k:f:\00"
@optarg = global i32 0
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Option -%c requires an argument.\0A\00"
@.str.2 = [23 x i8] c"Unknown option '-%c'.\0A\00"
@.str.3 = [34 x i8] c"Unknown option character '\\x%x'.\0A\00"
@stdin = global i32 0
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
store i64 0, i64* @opterr
br label %5
5: ; preds = %19, %2
%6 = phi i32 [ undef, %2 ], [ %20, %19 ]
br label %7
7: ; preds = %5, %7
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %7 [
i32 -1, label %9
i32 107, label %13
i32 102, label %16
i32 63, label %21
]
9: ; preds = %7
%10 = load i32, i32* @stdin
%11 = call i64 @fgets(i8* %4, i32 80, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %42, label %36
13: ; preds = %7
%14 = load i32, i32* @optarg
%15 = tail call i32 @strtol(i32 %14, i32* null, i32 0)
br label %19
16: ; preds = %7
%17 = load i32, i32* @optarg
%18 = tail call i32 @parsekey(i32 %17)
br label %19
19: ; preds = %16, %13
%20 = phi i32 [ %15, %13 ], [ %18, %16 ]
br label %5
21: ; preds = %7
%22 = load i8, i8* @optopt
%23 = icmp eq i8 %22, 107
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8 signext 107)
br label %42
27: ; preds = %21
%28 = tail call i32 @isprint(i8 signext %22)
%29 = icmp eq i32 %28, 0
%30 = load i32, i32* @stderr
%31 = load i8, i8* @optopt
br i1 %29, label %34, label %32
32: ; preds = %27
%33 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %31)
br label %42
34: ; preds = %27
%35 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8 signext %31)
br label %42
36: ; preds = %9, %36
%37 = call i32 @encrypt(i8* %4, i32 %6)
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%39 = load i32, i32* @stdin
%40 = call i64 @fgets(i8* %4, i32 80, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %36
42: ; preds = %36, %9, %24, %34, %32
%43 = phi i32 [ 1, %32 ], [ 1, %34 ], [ 1, %24 ], [ 0, %9 ], [ 0, %36 ]
ret i32 %43
}