#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*/ printf(char *, ...);
unsigned char strlen(char *);
void challenge5() {
  const char KEY[] = "ICE";
  char in[] = "Burning 'em, if you ain't quick and nimble\n"
              "I go crazy when I hear a cymbal";
  unsigned char i;
  printf("challenge 5:\n");
  for (i = 0; i < strlen(in); i++)
    printf("%02x", in[i] ^ KEY[i % 3]);
  printf("\n");
}


x86 assembly (clang, -O0):
<challenge5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0xec2(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xed4(%rip),%rsi
mov    $0x4b,%edx
call   1050 <memcpy@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x51(%rbp)
movzbl -0x51(%rbp),%eax
mov    %eax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,%cl
mov    -0x58(%rbp),%eax
movzbl %cl,%ecx
cmp    %ecx,%eax
jge    11c2 <challenge5+0x92>
movzbl -0x51(%rbp),%eax
movsbl -0x50(%rbp,%rax,1),%esi
movzbl -0x51(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movsbl -0x4(%rbp,%rax,1),%eax
xor    %eax,%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x51(%rbp),%al
add    $0x1,%al
mov    %al,-0x51(%rbp)
jmp    1168 <challenge5+0x38>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<challenge5>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
movups 0xf07(%rip),%xmm0
movups %xmm0,0x3b(%rsp)
movaps 0xef0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
call   1050 <strlen@plt>
test   %al,%al
je     11fb <challenge5+0xbb>
movabs $0xaaaaaaaaaaaaaaab,%r12
aa aa aa
lea    0xe4f(%rip),%r13
lea    0xe4c(%rip),%r14
mov    %rsp,%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    %rbx,%rax
mul    %r12
shr    %rdx
lea    (%rdx,%rdx,2),%rax
mov    %r13,%rcx
sub    %rax,%rcx
movzbl (%rcx,%rbx,1),%eax
xor    (%rsp,%rbx,1),%al
movsbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
movzbl %al,%eax
cmp    %rax,%rbx
jb     11c0 <challenge5+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.challenge5.KEY = [4 x i8] c"ICE\00"
@__const.challenge5.in = [75 x i8] c"Burning 'em, if you ain't quick and nimble\0AI go crazy when I hear a cymbal\00"
@.str = [14 x i8] c"challenge 5:\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @challenge5() {
%1 = alloca [4 x i8]
%2 = alloca [75 x i8]
%3 = alloca i8
%4 = bitcast [4 x i8]* %1 to i8*
%5 = bitcast [75 x i8]* %2 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %3
br label %7
7: ; preds = %29, %0
%8 = load i8, i8* %3
%9 = zext i8 %8 to i32
%10 = getelementptr inbounds [75 x i8], [75 x i8]* %2, i64 0, i64 0
%11 = call zeroext i8 @strlen(i8* %10)
%12 = zext i8 %11 to i32
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %32
14: ; preds = %7
%15 = load i8, i8* %3
%16 = zext i8 %15 to i64
%17 = getelementptr inbounds [75 x i8], [75 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = srem i32 %21, 3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = xor i32 %19, %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %14
%30 = load i8, i8* %3
%31 = add i8 %30, 1
store i8 %31, i8* %3
br label %7
32: ; preds = %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.challenge5.KEY = [4 x i8] c"ICE\00"
@__const.challenge5.in = [75 x i8] c"Burning 'em, if you ain't quick and nimble\0AI go crazy when I hear a cymbal\00"
@.str.1 = [5 x i8] c"%02x\00"
@str = [13 x i8] c"challenge 5:\00"
define void @challenge5() {
%1 = alloca [75 x i8]
%2 = getelementptr inbounds [75 x i8], [75 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = call zeroext i8 @strlen(i8* %2)
%5 = icmp eq i8 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %18, %6 ], [ 0, %0 ]
%8 = getelementptr inbounds [75 x i8], [75 x i8]* %1, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = trunc i64 %7 to i8
%11 = urem i8 %10, 3
%12 = zext i8 %11 to i64
%13 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.challenge5.KEY, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = xor i8 %14, %9
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %7, 1
%19 = call zeroext i8 @strlen(i8* %2)
%20 = zext i8 %19 to i64
%21 = icmp ult i64 %18, %20
br i1 %21, label %6, label %22
22: ; preds = %6, %0
%23 = call i32 @putchar(i32 10)
ret void
}