#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*/ affine(int /*<<< orphan*/, long, int, int);
int /*<<< orphan*/ coprime(long, int);
scalar_t__ errno;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
void *strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int encrypt = 1;
  int arg = 1;
  long int a = 0;
  int b = 0;
  if (argc == 4) {
    if (strcmp(argv[arg++], "-d") == 0)
      encrypt = 0;
    else
      usage();
  } else if (argc != 3) {
    usage();
  }
  errno = 0;
  a = strtol(argv[arg], NULL, 10);
  if (errno != 0 || a < 0 || !coprime(a, 26))
    usage();
  errno = 0;
  b = strtol(argv[++arg], NULL, 10);
  if (errno != 0 || b < 0 || b > 25)
    usage();
  affine(stdin, a, b, encrypt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    11d1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe56(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11c5 <main+0x75>
movl   $0x0,-0x14(%rbp)
jmp    11cc <main+0x7c>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    11e7 <main+0x97>
cmpl   $0x3,-0x8(%rbp)
je     11e2 <main+0x92>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    11e7 <main+0x97>
mov    0x2dea(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2dbe(%rip),%rax
cmpq   $0x0,(%rax)
jne    1246 <main+0xf6>
cmpq   $0x0,-0x20(%rbp)
jl     1246 <main+0xf6>
mov    -0x20(%rbp),%rdi
mov    $0x1a,%esi
call   1040 <coprime@plt>
cmp    $0x0,%eax
jne    124d <main+0xfd>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2d84(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d51(%rip),%rax
cmpq   $0x0,(%rax)
jne    12a5 <main+0x155>
cmpl   $0x0,-0x24(%rbp)
jl     12a5 <main+0x155>
cmpl   $0x19,-0x24(%rbp)
jle    12ac <main+0x15c>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1050 <affine@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    $0x1,%r14d
mov    $0x1,%ebx
cmp    $0x3,%edi
je     1197 <main+0x47>
cmp    $0x4,%edi
jne    118b <main+0x3b>
mov    0x8(%r12),%rdi
lea    0xe84(%rip),%rsi
call   1030 <strcmp@plt>
mov    $0x2,%ebx
test   %rax,%rax
je     1194 <main+0x44>
xor    %eax,%eax
call   1070 <usage@plt>
jmp    1197 <main+0x47>
xor    %r14d,%r14d
mov    0x2e3a(%rip),%r15
movq   $0x0,(%r15)
mov    %ebx,%ebx
mov    (%r12,%rbx,8),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbp
cmpq   $0x0,(%r15)
jne    11d6 <main+0x86>
test   %rbp,%rbp
js     11d6 <main+0x86>
mov    %rbp,%rdi
mov    $0x1a,%esi
call   1040 <coprime@plt>
test   %eax,%eax
jne    11dd <main+0x8d>
xor    %eax,%eax
call   1070 <usage@plt>
movq   $0x0,(%r15)
mov    0x8(%r12,%rbx,8),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
cmpq   $0x0,(%r15)
jne    1207 <main+0xb7>
test   %ebx,%ebx
js     1207 <main+0xb7>
cmp    $0x1a,%ebx
jl     120e <main+0xbe>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1050 <affine@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-d\00"
@errno = global i64 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 1, i32* %7
store i64 0, i64* %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %25
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
store i32 %15, i32* %7
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8*, i8** %13, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %12
store i32 0, i32* %6
br label %24
22: ; preds = %12
%23 = call i32 (...) @usage()
br label %24
24: ; preds = %22, %21
br label %31
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 3
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (...) @usage()
br label %30
30: ; preds = %28, %25
br label %31
31: ; preds = %30, %24
store i64 0, i64* @errno
%32 = load i8**, i8*** %5
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i8* @strtol(i8* %36, i32* null, i32 10)
%38 = ptrtoint i8* %37 to i64
store i64 %38, i64* %8
%39 = load i64, i64* @errno
%40 = icmp ne i64 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %31
%42 = load i64, i64* %8
%43 = icmp slt i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = load i64, i64* %8
%46 = call i32 @coprime(i64 %45, i32 26)
%47 = icmp ne i32 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %44, %41, %31
%49 = call i32 (...) @usage()
br label %50
50: ; preds = %48, %44
store i64 0, i64* @errno
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %51, i64 %54
%56 = load i8*, i8** %55
%57 = call i8* @strtol(i8* %56, i32* null, i32 10)
%58 = ptrtoint i8* %57 to i32
store i32 %58, i32* %9
%59 = load i64, i64* @errno
%60 = icmp ne i64 %59, 0
br i1 %60, label %67, label %61
61: ; preds = %50
%62 = load i32, i32* %9
%63 = icmp slt i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = load i32, i32* %9
%66 = icmp sgt i32 %65, 25
br i1 %66, label %67, label %69
67: ; preds = %64, %61, %50
%68 = call i32 (...) @usage()
br label %69
69: ; preds = %67, %64
%70 = load i32, i32* @stdin
%71 = load i64, i64* %8
%72 = load i32, i32* %9
%73 = load i32, i32* %6
%74 = call i32 @affine(i32 %70, i64 %71, i32 %72, i32 %73)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-d\00"
@errno = global i64 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %8 [
i32 4, label %3
i32 3, label %11
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2, %3
%9 = phi i32 [ 2, %3 ], [ 1, %2 ]
%10 = tail call i32 (...) @usage()
br label %11
11: ; preds = %8, %2, %3
%12 = phi i32 [ 0, %3 ], [ 1, %2 ], [ 1, %8 ]
%13 = phi i32 [ 2, %3 ], [ 1, %2 ], [ %9, %8 ]
store i64 0, i64* @errno
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i8* @strtol(i8* nocapture %16, i32* null, i32 10)
%18 = ptrtoint i8* %17 to i64
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
%21 = icmp slt i8* %17, null
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %26, label %23
23: ; preds = %11
%24 = tail call i32 @coprime(i64 %18, i32 26)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23, %11
%27 = tail call i32 (...) @usage()
br label %28
28: ; preds = %26, %23
store i64 0, i64* @errno
%29 = add nuw nsw i32 %13, 1
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i8* @strtol(i8* nocapture %32, i32* null, i32 10)
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i32
%36 = load i64, i64* @errno
%37 = icmp ne i64 %36, 0
%38 = icmp slt i32 %35, 0
%39 = select i1 %37, i1 true, i1 %38
%40 = icmp sgt i32 %35, 25
%41 = select i1 %39, i1 true, i1 %40
br i1 %41, label %42, label %44
42: ; preds = %28
%43 = tail call i32 (...) @usage()
br label %44
44: ; preds = %28, %42
%45 = load i32, i32* @stdin
%46 = tail call i32 @affine(i32 %45, i64 %18, i32 %35, i32 %12)
ret i32 0
}