#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 const *);
void challenge6() {
  const char one[] = "this is a test";
  const char two[] = "wokka wokka!!!";
  unsigned char c = 0;
  unsigned char i, j;
  printf("\nchallenge 6:\n");
  for (i = 0; i < strlen(one); i++)
    for (j = 0; j < 8; j++)
      c += (one[i] ^ two[i]) >> j & 1;
  printf("%d\n", c);
}


x86 assembly (clang, -O0):
<challenge6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x7(%rbp)
mov    0xec9(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xec1(%rip),%al
mov    %al,-0x1(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x1e(%rbp)
mov    0xeb6(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xeb0(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xea8(%rip),%al
mov    %al,-0x10(%rbp)
movb   $0x0,-0x1f(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x20(%rbp)
movzbl -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0xf(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,%cl
mov    -0x28(%rbp),%eax
movzbl %cl,%ecx
cmp    %ecx,%eax
jge    1206 <challenge6+0xe6>
movb   $0x0,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x8,%eax
jge    11f4 <challenge6+0xd4>
movzbl -0x20(%rbp),%eax
movsbl -0xf(%rbp,%rax,1),%eax
movzbl -0x20(%rbp),%ecx
movsbl -0x1e(%rbp,%rcx,1),%ecx
xor    %ecx,%eax
movzbl -0x21(%rbp),%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0x1,%ecx
movzbl -0x1f(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x1f(%rbp)
mov    -0x21(%rbp),%al
add    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    11b2 <challenge6+0x92>
jmp    11f9 <challenge6+0xd9>
mov    -0x20(%rbp),%al
add    $0x1,%al
mov    %al,-0x20(%rbp)
jmp    118e <challenge6+0x6e>
movzbl -0x1f(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<challenge6>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x74736574206120,%rax
mov    %rax,0xf(%rsp)
movabs $0x2073692073696874,%rax
69 73 20
mov    %rax,0x8(%rsp)
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
test   %al,%al
je     11fc <challenge6+0xcc>
xor    %r12d,%r12d
lea    0xe8e(%rip),%r15
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%r15,1),%eax
xor    0x8(%rsp,%r12,1),%al
mov    %eax,%ecx
and    $0x1,%cl
add    %bl,%cl
mov    %eax,%edx
shr    %dl
and    $0x1,%dl
add    %cl,%dl
mov    %eax,%ecx
shr    $0x2,%cl
and    $0x1,%cl
add    %dl,%cl
mov    %eax,%edx
shr    $0x3,%dl
and    $0x1,%dl
add    %cl,%dl
mov    %eax,%ecx
shr    $0x4,%cl
and    $0x1,%cl
add    %dl,%cl
mov    %eax,%edx
shr    $0x5,%dl
and    $0x1,%dl
add    %cl,%dl
mov    %eax,%ecx
shr    $0x6,%cl
and    $0x1,%cl
add    %dl,%cl
shr    $0x7,%al
mov    %eax,%ebx
add    %cl,%bl
add    $0x1,%r12
mov    %r14,%rdi
call   1040 <strlen@plt>
movzbl %al,%eax
cmp    %rax,%r12
jb     1190 <challenge6+0x60>
movzbl %bl,%esi
jmp    11fe <challenge6+0xce>
xor    %esi,%esi
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.challenge6.one = [15 x i8] c"this is a test\00"
@__const.challenge6.two = [15 x i8] c"wokka wokka!!!\00"
@.str = [15 x i8] c"\0Achallenge 6:\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @challenge6() {
%1 = alloca [15 x i8]
%2 = alloca [15 x i8]
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = bitcast [15 x i8]* %1 to i8*
%7 = bitcast [15 x i8]* %2 to i8*
store i8 0, i8* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %4
br label %9
9: ; preds = %45, %0
%10 = load i8, i8* %4
%11 = zext i8 %10 to i32
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%13 = call zeroext i8 @strlen(i8* %12)
%14 = zext i8 %13 to i32
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %48
16: ; preds = %9
store i8 0, i8* %5
br label %17
17: ; preds = %41, %16
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %44
21: ; preds = %17
%22 = load i8, i8* %4
%23 = zext i8 %22 to i64
%24 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8, i8* %4
%28 = zext i8 %27 to i64
%29 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = xor i32 %26, %31
%33 = load i8, i8* %5
%34 = zext i8 %33 to i32
%35 = ashr i32 %32, %34
%36 = and i32 %35, 1
%37 = load i8, i8* %3
%38 = zext i8 %37 to i32
%39 = add nsw i32 %38, %36
%40 = trunc i32 %39 to i8
store i8 %40, i8* %3
br label %41
41: ; preds = %21
%42 = load i8, i8* %5
%43 = add i8 %42, 1
store i8 %43, i8* %5
br label %17
44: ; preds = %17
br label %45
45: ; preds = %44
%46 = load i8, i8* %4
%47 = add i8 %46, 1
store i8 %47, i8* %4
br label %9
48: ; preds = %9
%49 = load i8, i8* %3
%50 = zext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %50)
ret void
}

LLVM IR (-O2):
@__const.challenge6.one = [15 x i8] c"this is a test\00"
@__const.challenge6.two = [15 x i8] c"wokka wokka!!!\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@str = [14 x i8] c"\0Achallenge 6:\00"
define void @challenge6() {
%1 = alloca [15 x i8]
%2 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = call zeroext i8 @strlen(i8* %2)
%5 = icmp eq i8 %4, 0
br i1 %5, label %42, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %36, %6 ], [ 0, %0 ]
%8 = phi i8 [ %35, %6 ], [ 0, %0 ]
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 %7
%10 = load i8, i8* %9
%11 = getelementptr inbounds [15 x i8], [15 x i8]* @__const.challenge6.two, i64 0, i64 %7
%12 = load i8, i8* %11
%13 = xor i8 %12, %10
%14 = and i8 %13, 1
%15 = add i8 %14, %8
%16 = lshr i8 %13, 1
%17 = and i8 %16, 1
%18 = add i8 %17, %15
%19 = lshr i8 %13, 2
%20 = and i8 %19, 1
%21 = add i8 %20, %18
%22 = lshr i8 %13, 3
%23 = and i8 %22, 1
%24 = add i8 %23, %21
%25 = lshr i8 %13, 4
%26 = and i8 %25, 1
%27 = add i8 %26, %24
%28 = lshr i8 %13, 5
%29 = and i8 %28, 1
%30 = add i8 %29, %27
%31 = lshr i8 %13, 6
%32 = and i8 %31, 1
%33 = add i8 %32, %30
%34 = lshr i8 %13, 7
%35 = add i8 %34, %33
%36 = add nuw nsw i64 %7, 1
%37 = call zeroext i8 @strlen(i8* %2)
%38 = zext i8 %37 to i64
%39 = icmp ult i64 %36, %38
br i1 %39, label %6, label %40
40: ; preds = %6
%41 = zext i8 %35 to i32
br label %42
42: ; preds = %40, %0
%43 = phi i32 [ 0, %0 ], [ %41, %40 ]
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
ret void
}