#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 strlen(char const *);
int /*<<< orphan*/ strncat(char *, char *, int);
void xorStringWithChar(char *dest, const char *src, const char xorVal) {
  int len = strlen(src);
  int i = 0;
  char tmp = '\0';
  for (i = 0; i < (len / 2); i++) {
    tmp = (((*(src + (i * 2)) << 4) & 0xf0) | (*(src + (i * 2) + 1) & 0x0f)) ^
          xorVal;
    strncat(dest, &tmp, 1);
  }
}


x86 assembly (clang, -O0):
<xorStringWithChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11ca <xorStringWithChar+0xaa>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
shl    $0x4,%eax
and    $0xf0,%eax
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%edx
shl    $0x1,%edx
movslq %edx,%rdx
movsbl 0x1(%rcx,%rdx,1),%ecx
and    $0xf,%ecx
or     %ecx,%eax
movsbl -0x11(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <xorStringWithChar+0x33>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xorStringWithChar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1181 <xorStringWithChar+0x61>
mov    %eax,%r13d
shr    %r13d
xor    %ebp,%ebp
lea    0x7(%rsp),%r12
xchg   %ax,%ax
movzbl (%rbx,%rbp,2),%eax
movzbl 0x1(%rbx,%rbp,2),%ecx
shl    $0x4,%al
and    $0xf,%cl
or     %al,%cl
xor    %r14b,%cl
mov    %cl,0x7(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <xorStringWithChar+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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