#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int hexCharToInt(int);
int intToHexChar(int);
int /*<<< orphan*/ isxdigit(int);
int /*<<< orphan*/ memcpy(int *, int const *, int);
void tweakBlock(const uint8_t *data, uint32_t blockNum, uint32_t tweak,
                uint8_t *tweakedBlock) {
  memcpy(tweakedBlock, data + 28 * blockNum, 28);
  memcpy(tweakedBlock + 28, &blockNum, sizeof(uint32_t));
  uint32_t pos = 0;
  while (tweak != 0) {
    while (!isxdigit(tweakedBlock[pos])) {
      pos++;
    }
    uint8_t digitTweak = tweak & 0xf;
    tweak >>= 4;
    uint8_t digit = hexCharToInt(tweakedBlock[pos]);
    tweakedBlock[pos] = intToHexChar((digit + digitTweak) % 16);
    pos++;
  }
}


x86 assembly (clang, -O0):
<tweakBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
imul   $0x1c,-0xc(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1c,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rdi
add    $0x70,%rdi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1229 <tweakBlock+0xe9>
jmp    11a1 <tweakBlock+0x61>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c6 <tweakBlock+0x86>
jmp    11d4 <tweakBlock+0x94>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a1 <tweakBlock+0x61>
mov    -0x10(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <hexCharToInt@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <intToHexChar@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <tweakBlock+0x52>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tweakBlock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,0x4(%rsp)
lea    (%rsi,%rsi,8),%eax
lea    (%rax,%rax,2),%eax
add    %esi,%eax
cltq
lea    (%rdi,%rax,4),%rsi
mov    %rcx,%rdi
mov    $0x1c,%edx
call   1040 <memcpy@plt>
lea    0x70(%r15),%rdi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
test   %r14d,%r14d
je     11ef <tweakBlock+0xaf>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15,%rbx,4),%ebp
mov    %ebp,%edi
call   1050 <isxdigit@plt>
add    $0x1,%rbx
test   %eax,%eax
je     11a0 <tweakBlock+0x60>
mov    %r14d,%r12d
and    $0xf,%r12d
mov    %r14d,%r13d
sar    $0x4,%r13d
mov    %ebp,%edi
call   1060 <hexCharToInt@plt>
lea    (%rax,%r12,1),%ecx
add    $0xf,%ecx
mov    %eax,%edi
add    %r12d,%edi
cmovns %edi,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%edi
call   1030 <intToHexChar@plt>
mov    %eax,-0x4(%r15,%rbx,4)
cmp    $0xf,%r14d
mov    %r13d,%r14d
ja     1190 <tweakBlock+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @tweakBlock(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = load i32*, i32** %8
%13 = load i32*, i32** %5
%14 = load i32, i32* %6
%15 = mul nsw i32 28, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %13, i64 %16
%18 = call i32 @memcpy(i32* %12, i32* %17, i32 28)
%19 = load i32*, i32** %8
%20 = getelementptr inbounds i32, i32* %19, i64 28
%21 = call i32 @memcpy(i32* %20, i32* %6, i32 4)
store i32 0, i32* %9
br label %22
22: ; preds = %38, %4
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %60
25: ; preds = %22
br label %26
26: ; preds = %35, %25
%27 = load i32*, i32** %8
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i32 @isxdigit(i32 %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %26
38: ; preds = %26
%39 = load i32, i32* %7
%40 = and i32 %39, 15
store i32 %40, i32* %10
%41 = load i32, i32* %7
%42 = ashr i32 %41, 4
store i32 %42, i32* %7
%43 = load i32*, i32** %8
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = call i32 @hexCharToInt(i32 %47)
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = load i32, i32* %10
%51 = add nsw i32 %49, %50
%52 = srem i32 %51, 16
%53 = call i32 @intToHexChar(i32 %52)
%54 = load i32*, i32** %8
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %22
60: ; preds = %22
ret void
}

LLVM IR (-O2):
define void @tweakBlock(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
store i32 %1, i32* %5
%6 = mul nsw i32 %1, 28
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = tail call i32 @memcpy(i32* %3, i32* %8, i32 28)
%10 = getelementptr inbounds i32, i32* %3, i64 28
%11 = call i32 @memcpy(i32* %10, i32* %5, i32 4)
%12 = icmp eq i32 %2, 0
br i1 %12, label %35, label %13
13: ; preds = %4, %25
%14 = phi i32 [ %28, %25 ], [ %2, %4 ]
%15 = phi i64 [ %33, %25 ], [ 0, %4 ]
%16 = shl i64 %15, 32
%17 = ashr exact i64 %16, 32
br label %18
18: ; preds = %18, %13
%19 = phi i64 [ %24, %18 ], [ %17, %13 ]
%20 = getelementptr inbounds i32, i32* %3, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @isxdigit(i32 %21)
%23 = icmp eq i32 %22, 0
%24 = add i64 %19, 1
br i1 %23, label %18, label %25
25: ; preds = %18
%26 = getelementptr inbounds i32, i32* %3, i64 %19
%27 = and i32 %14, 15
%28 = ashr i32 %14, 4
%29 = call i32 @hexCharToInt(i32 %21)
%30 = add nsw i32 %29, %27
%31 = srem i32 %30, 16
%32 = call i32 @intToHexChar(i32 %31)
store i32 %32, i32* %26
%33 = add i64 %19, 1
%34 = icmp ult i32 %14, 16
br i1 %34, label %35, label %13
35: ; preds = %25, %4
ret void
}