#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 */
unsigned char encipher(unsigned char const **, unsigned char const *,
                       unsigned char, unsigned char, unsigned char,
                       unsigned char const);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char);
bool crack_commercial(const unsigned char *rotors[6],
                      const unsigned char reflector[26],
                      const unsigned char plain_text[13],
                      const unsigned char cipher_text[13],
                      unsigned char answer[3]) {
  unsigned char n;
  unsigned char i;
  unsigned char j;
  unsigned char k;
  unsigned char c;
  bool bad_match;
  for (k = 0; k < 26; k++) {
    for (j = 0; j < 26; j++) {
      for (i = 0; i < 26; i++) {
        bad_match = false;
        for (c = 0; c < 13; c++) {
          n = encipher(rotors, reflector, (i + c) % 26, j, k, plain_text[c]);
          if (n != cipher_text[c]) {
            bad_match = true;
            break;
          }
        }
        if (!bad_match) {
          printf("Match at: %d, %d, %d.\n", i, j, k);
          answer[0] = i;
          answer[1] = j;
          answer[2] = k;
          return (true);
        }
      }
    }
  }
  return (false);
}


x86 assembly (clang, -O0):
<crack_commercial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movb   $0x0,-0x34(%rbp)
movzbl -0x34(%rbp),%eax
cmp    $0x1a,%eax
jge    1283 <crack_commercial+0x163>
movb   $0x0,-0x33(%rbp)
movzbl -0x33(%rbp),%eax
cmp    $0x1a,%eax
jge    1271 <crack_commercial+0x151>
movb   $0x0,-0x32(%rbp)
movzbl -0x32(%rbp),%eax
cmp    $0x1a,%eax
jge    125f <crack_commercial+0x13f>
movl   $0x0,-0x3c(%rbp)
movb   $0x0,-0x35(%rbp)
movzbl -0x35(%rbp),%eax
cmp    $0xd,%eax
jge    11fe <crack_commercial+0xde>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movzbl -0x32(%rbp),%eax
movzbl -0x35(%rbp),%ecx
add    %ecx,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    -0x33(%rbp),%cl
mov    -0x34(%rbp),%r8b
mov    -0x20(%rbp),%rax
movzbl -0x35(%rbp),%r9d
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl (%rax,%r9,1),%r9d
call   1040 <encipher@plt>
mov    %al,-0x31(%rbp)
movzbl -0x31(%rbp),%eax
mov    -0x28(%rbp),%rcx
movzbl -0x35(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11ec <crack_commercial+0xcc>
movl   $0x1,-0x3c(%rbp)
jmp    11fe <crack_commercial+0xde>
jmp    11f1 <crack_commercial+0xd1>
mov    -0x35(%rbp),%al
add    $0x1,%al
mov    %al,-0x35(%rbp)
jmp    117a <crack_commercial+0x5a>
cmpl   $0x0,-0x3c(%rbp)
jne    124d <crack_commercial+0x12d>
mov    -0x32(%rbp),%cl
mov    -0x33(%rbp),%al
lea    0xdeb(%rip),%rdi
movzbl %cl,%esi
movzbl %al,%edx
movzbl -0x34(%rbp),%ecx
call   1030 <printf@plt>
mov    -0x32(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x33(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x34(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,0x2(%rax)
movl   $0x1,-0x4(%rbp)
jmp    128a <crack_commercial+0x16a>
jmp    1252 <crack_commercial+0x132>
mov    -0x32(%rbp),%al
add    $0x1,%al
mov    %al,-0x32(%rbp)
jmp    1162 <crack_commercial+0x42>
jmp    1264 <crack_commercial+0x144>
mov    -0x33(%rbp),%al
add    $0x1,%al
mov    %al,-0x33(%rbp)
jmp    1151 <crack_commercial+0x31>
jmp    1276 <crack_commercial+0x156>
mov    -0x34(%rbp),%al
add    $0x1,%al
mov    %al,-0x34(%rbp)
jmp    1140 <crack_commercial+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crack_commercial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,0x18(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    %r13d,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax)
movzwl %r12w,%eax
imul   $0x4ec5,%eax,%eax
shr    $0x13,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
mov    %r13d,%eax
sub    %cl,%al
movzbl %al,%eax
add    %ebx,%eax
mov    0x28(%rsp),%rcx
movzbl (%rcx,%rbx,1),%r9d
movzbl %al,%edx
movzbl %r15b,%ebp
movzbl 0x8(%rsp),%r14d
mov    0x18(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1040 <encipher@plt>
mov    0x30(%rsp),%rcx
cmp    (%rcx,%rbx,1),%al
jne    11d0 <crack_commercial+0xb0>
add    $0x1,%rbx
add    $0x1,%r12d
cmp    $0xd,%rbx
jne    1160 <crack_commercial+0x40>
jmp    1205 <crack_commercial+0xe5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13d
cmp    $0x1a,%r13w
jne    1154 <crack_commercial+0x34>
add    $0x1,%r15b
cmp    $0x1a,%r15b
jne    1151 <crack_commercial+0x31>
mov    0x8(%rsp),%rax
add    $0x1,%al
mov    %rax,0x8(%rsp)
cmp    $0x1a,%al
jne    114e <crack_commercial+0x2e>
xor    %eax,%eax
jmp    1233 <crack_commercial+0x113>
movzbl %r13b,%esi
lea    0xdf0(%rip),%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1030 <printf@plt>
mov    0x10(%rsp),%rax
mov    %r13b,(%rax)
mov    %r15b,0x1(%rax)
mov    0x8(%rsp),%rcx
mov    %cl,0x2(%rax)
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Match at: %d, %d, %d.\0A\00"
define i32 @crack_commercial(i8** %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
%16 = alloca i8
%17 = alloca i32
store i8** %0, i8*** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8 0, i8* %15
br label %18
18: ; preds = %95, %5
%19 = load i8, i8* %15
%20 = zext i8 %19 to i32
%21 = icmp slt i32 %20, 26
br i1 %21, label %22, label %98
22: ; preds = %18
store i8 0, i8* %14
br label %23
23: ; preds = %91, %22
%24 = load i8, i8* %14
%25 = zext i8 %24 to i32
%26 = icmp slt i32 %25, 26
br i1 %26, label %27, label %94
27: ; preds = %23
store i8 0, i8* %13
br label %28
28: ; preds = %87, %27
%29 = load i8, i8* %13
%30 = zext i8 %29 to i32
%31 = icmp slt i32 %30, 26
br i1 %31, label %32, label %90
32: ; preds = %28
store i32 0, i32* %17
store i8 0, i8* %16
br label %33
33: ; preds = %66, %32
%34 = load i8, i8* %16
%35 = zext i8 %34 to i32
%36 = icmp slt i32 %35, 13
br i1 %36, label %37, label %69
37: ; preds = %33
%38 = load i8**, i8*** %7
%39 = load i8*, i8** %8
%40 = load i8, i8* %13
%41 = zext i8 %40 to i32
%42 = load i8, i8* %16
%43 = zext i8 %42 to i32
%44 = add nsw i32 %41, %43
%45 = srem i32 %44, 26
%46 = trunc i32 %45 to i8
%47 = load i8, i8* %14
%48 = load i8, i8* %15
%49 = load i8*, i8** %9
%50 = load i8, i8* %16
%51 = zext i8 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = call zeroext i8 @encipher(i8** %38, i8* %39, i8 zeroext %46, i8 zeroext %47, i8 zeroext %48, i8 zeroext %53)
store i8 %54, i8* %12
%55 = load i8, i8* %12
%56 = zext i8 %55 to i32
%57 = load i8*, i8** %10
%58 = load i8, i8* %16
%59 = zext i8 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %56, %62
br i1 %63, label %64, label %65
64: ; preds = %37
store i32 1, i32* %17
br label %69
65: ; preds = %37
br label %66
66: ; preds = %65
%67 = load i8, i8* %16
%68 = add i8 %67, 1
store i8 %68, i8* %16
br label %33
69: ; preds = %64, %33
%70 = load i32, i32* %17
%71 = icmp ne i32 %70, 0
br i1 %71, label %86, label %72
72: ; preds = %69
%73 = load i8, i8* %13
%74 = load i8, i8* %14
%75 = load i8, i8* %15
%76 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 zeroext %73, i8 zeroext %74, i8 zeroext %75)
%77 = load i8, i8* %13
%78 = load i8*, i8** %11
%79 = getelementptr inbounds i8, i8* %78, i64 0
store i8 %77, i8* %79
%80 = load i8, i8* %14
%81 = load i8*, i8** %11
%82 = getelementptr inbounds i8, i8* %81, i64 1
store i8 %80, i8* %82
%83 = load i8, i8* %15
%84 = load i8*, i8** %11
%85 = getelementptr inbounds i8, i8* %84, i64 2
store i8 %83, i8* %85
store i32 1, i32* %6
br label %99
86: ; preds = %69
br label %87
87: ; preds = %86
%88 = load i8, i8* %13
%89 = add i8 %88, 1
store i8 %89, i8* %13
br label %28
90: ; preds = %28
br label %91
91: ; preds = %90
%92 = load i8, i8* %14
%93 = add i8 %92, 1
store i8 %93, i8* %14
br label %23
94: ; preds = %23
br label %95
95: ; preds = %94
%96 = load i8, i8* %15
%97 = add i8 %96, 1
store i8 %97, i8* %15
br label %18
98: ; preds = %18
store i32 0, i32* %6
br label %99
99: ; preds = %98, %72
%100 = load i32, i32* %6
ret i32 %100
}

LLVM IR (-O2):
@.str = [23 x i8] c"Match at: %d, %d, %d.\0A\00"
define i32 @crack_commercial(i8** %0, i8* %1, i8* nocapture %2, i8* nocapture %3, i8* nocapture writeonly %4) {
br label %6
6: ; preds = %5, %38
%7 = phi i8 [ 0, %5 ], [ %39, %38 ]
br label %8
8: ; preds = %6, %35
%9 = phi i8 [ 0, %6 ], [ %36, %35 ]
br label %10
10: ; preds = %8, %32
%11 = phi i16 [ 0, %8 ], [ %33, %32 ]
br label %15
12: ; preds = %15
%13 = add nuw nsw i64 %16, 1
%14 = icmp eq i64 %13, 13
br i1 %14, label %27, label %15
15: ; preds = %10, %12
%16 = phi i64 [ 0, %10 ], [ %13, %12 ]
%17 = trunc i64 %16 to i16
%18 = add nuw nsw i16 %11, %17
%19 = urem i16 %18, 26
%20 = trunc i16 %19 to i8
%21 = getelementptr inbounds i8, i8* %2, i64 %16
%22 = load i8, i8* %21
%23 = tail call zeroext i8 @encipher(i8** %0, i8* %1, i8 zeroext %20, i8 zeroext %9, i8 zeroext %7, i8 zeroext %22)
%24 = getelementptr inbounds i8, i8* %3, i64 %16
%25 = load i8, i8* %24
%26 = icmp eq i8 %23, %25
br i1 %26, label %12, label %32
27: ; preds = %12
%28 = trunc i16 %11 to i8
%29 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 zeroext %28, i8 zeroext %9, i8 zeroext %7)
store i8 %28, i8* %4
%30 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %9, i8* %30
%31 = getelementptr inbounds i8, i8* %4, i64 2
store i8 %7, i8* %31
br label %41
32: ; preds = %15
%33 = add nuw nsw i16 %11, 1
%34 = icmp eq i16 %33, 26
br i1 %34, label %35, label %10
35: ; preds = %32
%36 = add nuw nsw i8 %9, 1
%37 = icmp eq i8 %36, 26
br i1 %37, label %38, label %8
38: ; preds = %35
%39 = add nuw nsw i8 %7, 1
%40 = icmp eq i8 %39, 26
br i1 %40, label %41, label %6
41: ; preds = %38, %27
%42 = phi i32 [ 1, %27 ], [ 0, %38 ]
ret i32 %42
}