#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 xlat(unsigned char *, unsigned char);
int xlatTest() {
  unsigned char notV[256];
  unsigned char xlated[256];
  int i;
  int failures = 0;
  for (i = 0; i < 256; i++) {
    notV[i] = (unsigned char)~i;
  }
  for (i = 0; i < 256; i++) {
    xlated[i] = xlat(notV, (unsigned char)i);
  }
  for (i = 0; i < 256; i++) {
    if (xlated[i] != notV[i]) {
      printf("XLAT failed : got %02x expected %02x\n", xlated[i], notV[i]);
      failures++;
    }
  }
  printf("XLAT test %s\n", failures ? "FAILED" : "Passed");
  return failures;
}


x86 assembly (clang, -O0):
<xlatTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x208(%rbp)
movl   $0x0,-0x204(%rbp)
cmpl   $0x100,-0x204(%rbp)
jge    117c <xlatTest+0x5c>
mov    -0x204(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,%cl
movslq -0x204(%rbp),%rax
mov    %cl,-0x100(%rbp,%rax,1)
mov    -0x204(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x204(%rbp)
jmp    113f <xlatTest+0x1f>
movl   $0x0,-0x204(%rbp)
cmpl   $0x100,-0x204(%rbp)
jge    11cf <xlatTest+0xaf>
lea    -0x100(%rbp),%rdi
mov    -0x204(%rbp),%eax
movzbl %al,%esi
call   1040 <xlat@plt>
mov    %al,%cl
movslq -0x204(%rbp),%rax
mov    %cl,-0x200(%rbp,%rax,1)
mov    -0x204(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x204(%rbp)
jmp    1186 <xlatTest+0x66>
movl   $0x0,-0x204(%rbp)
cmpl   $0x100,-0x204(%rbp)
jge    1263 <xlatTest+0x143>
movslq -0x204(%rbp),%rax
movzbl -0x200(%rbp,%rax,1),%eax
ff
movslq -0x204(%rbp),%rcx
movzbl -0x100(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
je     124a <xlatTest+0x12a>
movslq -0x204(%rbp),%rax
movzbl -0x200(%rbp,%rax,1),%esi
ff
movslq -0x204(%rbp),%rax
movzbl -0x100(%rbp,%rax,1),%edx
ff
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x208(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x208(%rbp)
jmp    124f <xlatTest+0x12f>
mov    -0x204(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x204(%rbp)
jmp    11d9 <xlatTest+0xb9>
mov    -0x208(%rbp),%ecx
lea    0xdcb(%rip),%rsi
lea    0xdbd(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x208(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xlatTest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
movaps 0xece(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xedb(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee3(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xee7(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xeeb(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xeef(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xef0(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xef2(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xef3(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xef4(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xef5(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xef6(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
xor    %ebp,%ebp
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
movzbl %bpl,%esi
mov    %rbx,%rdi
call   1040 <xlat@plt>
mov    %al,0x100(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0x100,%rbp
jne    1210 <xlatTest+0xf0>
lea    0xec9(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    124d <xlatTest+0x12d>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x100,%rbx
je     126d <xlatTest+0x14d>
movzbl 0x100(%rsp,%rbx,1),%esi
movzbl (%rsp,%rbx,1),%edx
cmp    %dl,%sil
je     1240 <xlatTest+0x120>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
jmp    1240 <xlatTest+0x120>
test   %ebp,%ebp
lea    0xec5(%rip),%rax
lea    0xeb7(%rip),%rsi
cmove  %rax,%rsi
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"XLAT failed : got %02x expected %02x\0A\00"
@.str.1 = [14 x i8] c"XLAT test %s\0A\00"
@.str.2 = [7 x i8] c"FAILED\00"
@.str.3 = [7 x i8] c"Passed\00"
define i32 @xlatTest() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 256
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i32, i32* %3
%10 = xor i32 %9, -1
%11 = trunc i32 %10 to i8
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %13
store i8 %11, i8* %14
br label %15
15: ; preds = %8
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %5
store i32 0, i32* %3
br label %19
19: ; preds = %30, %18
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 256
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%24 = load i32, i32* %3
%25 = trunc i32 %24 to i8
%26 = call zeroext i8 @xlat(i8* %23, i8 zeroext %25)
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %22
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %19
33: ; preds = %19
store i32 0, i32* %3
br label %34
34: ; preds = %64, %33
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 256
br i1 %36, label %37, label %67
37: ; preds = %34
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = icmp ne i32 %42, %47
br i1 %48, label %49, label %63
49: ; preds = %37
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %54, i32 %59)
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %63
63: ; preds = %49, %37
br label %64
64: ; preds = %63
%65 = load i32, i32* %3
%66 = add nsw i32 %65, 1
store i32 %66, i32* %3
br label %34
67: ; preds = %34
%68 = load i32, i32* %4
%69 = icmp ne i32 %68, 0
%70 = zext i1 %69 to i64
%71 = select i1 %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %71)
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@.str = [38 x i8] c"XLAT failed : got %02x expected %02x\0A\00"
@.str.1 = [14 x i8] c"XLAT test %s\0A\00"
@.str.2 = [7 x i8] c"FAILED\00"
@.str.3 = [7 x i8] c"Passed\00"
define i32 @xlatTest() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = bitcast [256 x i8]* %1 to <16 x i8>*
store <16 x i8> <i8 -1, i8 -2, i8 -3, i8 -4, i8 -5, i8 -6, i8 -7, i8 -8, i8 -9, i8 -10, i8 -11, i8 -12, i8 -13, i8 -14, i8 -15, i8 -16>, <16 x i8>* %5
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 16
%7 = bitcast i8* %6 to <16 x i8>*
store <16 x i8> <i8 -17, i8 -18, i8 -19, i8 -20, i8 -21, i8 -22, i8 -23, i8 -24, i8 -25, i8 -26, i8 -27, i8 -28, i8 -29, i8 -30, i8 -31, i8 -32>, <16 x i8>* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 32
%9 = bitcast i8* %8 to <16 x i8>*
store <16 x i8> <i8 -33, i8 -34, i8 -35, i8 -36, i8 -37, i8 -38, i8 -39, i8 -40, i8 -41, i8 -42, i8 -43, i8 -44, i8 -45, i8 -46, i8 -47, i8 -48>, <16 x i8>* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 48
%11 = bitcast i8* %10 to <16 x i8>*
store <16 x i8> <i8 -49, i8 -50, i8 -51, i8 -52, i8 -53, i8 -54, i8 -55, i8 -56, i8 -57, i8 -58, i8 -59, i8 -60, i8 -61, i8 -62, i8 -63, i8 -64>, <16 x i8>* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 64
%13 = bitcast i8* %12 to <16 x i8>*
store <16 x i8> <i8 -65, i8 -66, i8 -67, i8 -68, i8 -69, i8 -70, i8 -71, i8 -72, i8 -73, i8 -74, i8 -75, i8 -76, i8 -77, i8 -78, i8 -79, i8 -80>, <16 x i8>* %13
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 80
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> <i8 -81, i8 -82, i8 -83, i8 -84, i8 -85, i8 -86, i8 -87, i8 -88, i8 -89, i8 -90, i8 -91, i8 -92, i8 -93, i8 -94, i8 -95, i8 -96>, <16 x i8>* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 96
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> <i8 -97, i8 -98, i8 -99, i8 -100, i8 -101, i8 -102, i8 -103, i8 -104, i8 -105, i8 -106, i8 -107, i8 -108, i8 -109, i8 -110, i8 -111, i8 -112>, <16 x i8>* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 112
%19 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> <i8 -113, i8 -114, i8 -115, i8 -116, i8 -117, i8 -118, i8 -119, i8 -120, i8 -121, i8 -122, i8 -123, i8 -124, i8 -125, i8 -126, i8 -127, i8 -128>, <16 x i8>* %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 128
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> <i8 127, i8 126, i8 125, i8 124, i8 123, i8 122, i8 121, i8 120, i8 119, i8 118, i8 117, i8 116, i8 115, i8 114, i8 113, i8 112>, <16 x i8>* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 144
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> <i8 111, i8 110, i8 109, i8 108, i8 107, i8 106, i8 105, i8 104, i8 103, i8 102, i8 101, i8 100, i8 99, i8 98, i8 97, i8 96>, <16 x i8>* %23
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 160
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> <i8 95, i8 94, i8 93, i8 92, i8 91, i8 90, i8 89, i8 88, i8 87, i8 86, i8 85, i8 84, i8 83, i8 82, i8 81, i8 80>, <16 x i8>* %25
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 176
%27 = bitcast i8* %26 to <16 x i8>*
store <16 x i8> <i8 79, i8 78, i8 77, i8 76, i8 75, i8 74, i8 73, i8 72, i8 71, i8 70, i8 69, i8 68, i8 67, i8 66, i8 65, i8 64>, <16 x i8>* %27
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 192
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> <i8 63, i8 62, i8 61, i8 60, i8 59, i8 58, i8 57, i8 56, i8 55, i8 54, i8 53, i8 52, i8 51, i8 50, i8 49, i8 48>, <16 x i8>* %29
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 208
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> <i8 47, i8 46, i8 45, i8 44, i8 43, i8 42, i8 41, i8 40, i8 39, i8 38, i8 37, i8 36, i8 35, i8 34, i8 33, i8 32>, <16 x i8>* %31
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 224
%33 = bitcast i8* %32 to <16 x i8>*
store <16 x i8> <i8 31, i8 30, i8 29, i8 28, i8 27, i8 26, i8 25, i8 24, i8 23, i8 22, i8 21, i8 20, i8 19, i8 18, i8 17, i8 16>, <16 x i8>* %33
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 240
%35 = bitcast i8* %34 to <16 x i8>*
store <16 x i8> <i8 15, i8 14, i8 13, i8 12, i8 11, i8 10, i8 9, i8 8, i8 7, i8 6, i8 5, i8 4, i8 3, i8 2, i8 1, i8 0>, <16 x i8>* %35
br label %36
36: ; preds = %0, %36
%37 = phi i64 [ %41, %36 ], [ 0, %0 ]
%38 = trunc i64 %37 to i8
%39 = call zeroext i8 @xlat(i8* %3, i8 zeroext %38)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %37
store i8 %39, i8* %40
%41 = add nuw nsw i64 %37, 1
%42 = icmp eq i64 %41, 256
br i1 %42, label %43, label %36
43: ; preds = %36, %56
%44 = phi i64 [ %58, %56 ], [ 0, %36 ]
%45 = phi i32 [ %57, %56 ], [ 0, %36 ]
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %44
%47 = load i8, i8* %46
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %44
%49 = load i8, i8* %48
%50 = icmp eq i8 %47, %49
br i1 %50, label %56, label %51
51: ; preds = %43
%52 = zext i8 %49 to i32
%53 = zext i8 %47 to i32
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %53, i32 %52)
%55 = add nsw i32 %45, 1
br label %56
56: ; preds = %43, %51
%57 = phi i32 [ %55, %51 ], [ %45, %43 ]
%58 = add nuw nsw i64 %44, 1
%59 = icmp eq i64 %58, 256
br i1 %59, label %60, label %43
60: ; preds = %56
%61 = icmp eq i32 %57, 0
%62 = select i1 %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %62)
ret i32 %57
}