#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 */
char asciiToHex(char const);
char hexToAscii(char);
int strlen(char const *);
void xorStrings(char *dest, const char *src1, const char *src2) {
  char valSrc1 = 0;
  char valSrc2 = 0;
  char xorVal = 0;
  int len = strlen(src1);
  int i = 0;
  for (i = 0; i < len; i++) {
    valSrc1 = asciiToHex(*(src1 + i));
    valSrc2 = asciiToHex(*(src2 + i));
    xorVal = valSrc1 ^ valSrc2;
    xorVal = hexToAscii(xorVal);
    dest[i] = xorVal;
  }
}


x86 assembly (clang, -O0):
<xorStrings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x1a(%rbp)
movb   $0x0,-0x1b(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d3 <xorStrings+0xa3>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <asciiToHex@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <asciiToHex@plt>
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x1b(%rbp)
movsbl -0x1b(%rbp),%edi
call   1030 <hexToAscii@plt>
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116a <xorStrings+0x3a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xorStrings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    118d <xorStrings+0x5d>
mov    %eax,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r12,%rbp,1),%edi
call   1050 <asciiToHex@plt>
mov    %eax,%ebx
movsbl (%r14,%rbp,1),%edi
call   1050 <asciiToHex@plt>
xor    %bl,%al
movsbl %al,%edi
call   1030 <hexToAscii@plt>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <xorStrings+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @xorStrings(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8 0, i8* %7
store i8 0, i8* %8
store i8 0, i8* %9
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %10
store i32 0, i32* %11
store i32 0, i32* %11
br label %14
14: ; preds = %44, %3
%15 = load i32, i32* %11
%16 = load i32, i32* %10
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %47
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call signext i8 @asciiToHex(i8 signext %23)
store i8 %24, i8* %7
%25 = load i8*, i8** %6
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call signext i8 @asciiToHex(i8 signext %29)
store i8 %30, i8* %8
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = load i8, i8* %8
%34 = sext i8 %33 to i32
%35 = xor i32 %32, %34
%36 = trunc i32 %35 to i8
store i8 %36, i8* %9
%37 = load i8, i8* %9
%38 = call signext i8 @hexToAscii(i8 signext %37)
store i8 %38, i8* %9
%39 = load i8, i8* %9
%40 = load i8*, i8** %4
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %18
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %14
47: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @xorStrings(i8* nocapture writeonly %0, i8* %1, i8* nocapture %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %19, %8 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = tail call signext i8 @asciiToHex(i8 signext %11)
%13 = getelementptr inbounds i8, i8* %2, i64 %9
%14 = load i8, i8* %13
%15 = tail call signext i8 @asciiToHex(i8 signext %14)
%16 = xor i8 %15, %12
%17 = tail call signext i8 @hexToAscii(i8 signext %16)
%18 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %17, i8* %18
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %8, %3
ret void
}