#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*/ hex_decode(char const *, unsigned char *, int,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ xor_key_guess_sb(unsigned char *, int, int, unsigned char *);
int /*<<< orphan*/ xor_perform(unsigned char *, int, int, unsigned char *, int,
                               unsigned char *, int);
void set_1_challenge_3() {
  const char *input =
      "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736";
  const char *expected = "Cooking MC's like a pound of bacon";
  unsigned char bytes[34];
  unsigned char bytes_decrypted[35];
  unsigned char key;
  hex_decode(input, bytes, 34, NULL);
  xor_key_guess_sb(bytes, 34, 1, &key);
  xor_perform(bytes, 34, 1, &key, 1, bytes_decrypted, 34);
  bytes_decrypted[34] = 0;
  printf("Set 1 Challenge 3: %s\n",
         strcmp((char *)bytes_decrypted, expected) == 0 ? "PASS" : "FAIL");
}


x86 assembly (clang, -O0):
<set_1_challenge_3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe9e(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xed8(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x22,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <hex_decode@plt>
lea    -0x40(%rbp),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
lea    -0x71(%rbp),%rcx
call   1050 <xor_key_guess_sb@plt>
lea    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%r9
mov    $0x22,%esi
mov    $0x1,%r8d
lea    -0x71(%rbp),%rcx
mov    %r8d,%edx
movl   $0x22,(%rsp)
call   1070 <xor_perform@plt>
movb   $0x0,-0x4e(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
lea    0xea5(%rip),%rsi
lea    0xe99(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_1_challenge_3>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xea0(%rip),%rdi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x22,%edx
xor    %ecx,%ecx
call   1040 <hex_decode@plt>
lea    0xf(%rsp),%r14
mov    %rbx,%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <xor_key_guess_sb@plt>
movl   $0x22,(%rsp)
lea    0x10(%rsp),%r15
mov    %rbx,%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
mov    %r15,%r9
call   1070 <xor_perform@plt>
movb   $0x0,0x32(%rsp)
lea    0xe81(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xea9(%rip),%rax
lea    0xea7(%rip),%rsi
cmove  %rax,%rsi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [69 x i8] c"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\00"
@.str.1 = [35 x i8] c"Cooking MC's like a pound of bacon\00"
@.str.2 = [23 x i8] c"Set 1 Challenge 3: %s\0A\00"
@.str.3 = [5 x i8] c"PASS\00"
@.str.4 = [5 x i8] c"FAIL\00"
define void @set_1_challenge_3() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [34 x i8]
%4 = alloca [35 x i8]
%5 = alloca i8
store i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %1
%7 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%8 = call i32 @hex_decode(i8* %6, i8* %7, i32 34, i32* null)
%9 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%10 = call i32 @xor_key_guess_sb(i8* %9, i32 34, i32 1, i8* %5)
%11 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [35 x i8], [35 x i8]* %4, i64 0, i64 0
%13 = call i32 @xor_perform(i8* %11, i32 34, i32 1, i8* %5, i32 1, i8* %12, i32 34)
%14 = getelementptr inbounds [35 x i8], [35 x i8]* %4, i64 0, i64 34
store i8 0, i8* %14
%15 = getelementptr inbounds [35 x i8], [35 x i8]* %4, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = call i64 @strcmp(i8* %15, i8* %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %20)
ret void
}

LLVM IR (-O2):
@.str = [69 x i8] c"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736\00"
@.str.1 = [35 x i8] c"Cooking MC's like a pound of bacon\00"
@.str.2 = [23 x i8] c"Set 1 Challenge 3: %s\0A\00"
@.str.3 = [5 x i8] c"PASS\00"
@.str.4 = [5 x i8] c"FAIL\00"
define void @set_1_challenge_3() {
%1 = alloca [34 x i8]
%2 = alloca [35 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [35 x i8], [35 x i8]* %2, i64 0, i64 0
%6 = call i32 @hex_decode(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8* %4, i32 34, i32* null)
%7 = call i32 @xor_key_guess_sb(i8* %4, i32 34, i32 1, i8* %3)
%8 = call i32 @xor_perform(i8* %4, i32 34, i32 1, i8* %3, i32 1, i8* %5, i32 34)
%9 = getelementptr inbounds [35 x i8], [35 x i8]* %2, i64 0, i64 34
store i8 0, i8* %9
%10 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %12)
ret void
}