#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*/ libkeccak_behex_lower(char *, char const *, int);
int /*<<< orphan*/ libkeccak_behex_upper(char *, char const *, int);
int /*<<< orphan*/ libkeccak_unhex(char *, char const *);
int /*<<< orphan*/ memcmp(unsigned char const *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char const *);
int test_hex(void) {
  const unsigned char bindata[] = {0x04, 0x2F, 0x12, 0x83,
                                   0xFF, 0x80, 0xA3, 0x00};
  const char hexdata_upper[] = "042F1283FF80A300";
  const char hexdata_lower[] = "042f1283ff80a300";
  char hextest[2 * 8 + 1];
  printf("Testing libkeccak_behex_lower: ");
  libkeccak_behex_lower(hextest, (const char *)bindata, 8);
  if (!strcmp(hextest, hexdata_lower)) {
    printf("OK\n");
  } else {
    printf("Fail\n");
    return -1;
  }
  printf("Testing libkeccak_behex_upper: ");
  libkeccak_behex_upper(hextest, (const char *)bindata, 8);
  if (!strcmp(hextest, hexdata_upper)) {
    printf("OK\n");
  } else {
    printf("Fail\n");
    return -1;
  }
  printf("Testing libkeccak_unhex on uppercase: ");
  libkeccak_unhex(hextest, hexdata_upper);
  if (!memcmp(bindata, hextest, 8 * sizeof(char))) {
    printf("OK\n");
  } else {
    printf("Fail\n");
    return -1;
  }
  printf("Testing libkeccak_unhex on lowercase: ");
  libkeccak_unhex(hextest, hexdata_lower);
  if (!memcmp(bindata, hextest, 8 * sizeof(char))) {
    printf("OK\n");
  } else {
    printf("Fail\n");
    return -1;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xf26(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf23(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xf21(%rip),%al
mov    %al,-0x10(%rbp)
mov    0xf27(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xf24(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xf22(%rip),%al
mov    %al,-0x30(%rbp)
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x8,%edx
call   1080 <libkeccak_behex_lower@plt>
lea    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11f6 <test_hex+0x96>
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
jmp    120e <test_hex+0xae>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1338 <test_hex+0x1d8>
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x8,%edx
call   1050 <libkeccak_behex_upper@plt>
lea    -0x60(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1253 <test_hex+0xf3>
lea    0xddf(%rip),%rdi
call   1040 <printf@plt>
jmp    126b <test_hex+0x10b>
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1338 <test_hex+0x1d8>
lea    0xde0(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <libkeccak_unhex@plt>
lea    -0xc(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x8,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    12b0 <test_hex+0x150>
lea    0xd82(%rip),%rdi
call   1040 <printf@plt>
jmp    12c8 <test_hex+0x168>
lea    0xd75(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1338 <test_hex+0x1d8>
lea    0xdaa(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <libkeccak_unhex@plt>
lea    -0xc(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x8,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    130d <test_hex+0x1ad>
lea    0xd25(%rip),%rdi
call   1040 <printf@plt>
jmp    1325 <test_hex+0x1c5>
lea    0xd18(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1338 <test_hex+0x1d8>
lea    0xcfe(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hex>:
push   %rbx
sub    $0x70,%rsp
movabs $0xa380ff83122f04,%rax
mov    %rax,0x8(%rsp)
movaps 0xe65(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movb   $0x0,0x60(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movb   $0x0,0x40(%rsp)
lea    0xe74(%rip),%rdi
call   1060 <printf@plt>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   10a0 <libkeccak_behex_lower@plt>
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    12b2 <test_hex+0x132>
lea    0xeca(%rip),%rdi
call   1050 <puts@plt>
lea    0xe50(%rip),%rdi
call   1060 <printf@plt>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1070 <libkeccak_behex_upper@plt>
lea    0x50(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    12b2 <test_hex+0x132>
lea    0xe86(%rip),%rdi
call   1050 <puts@plt>
lea    0xe2c(%rip),%rdi
call   1060 <printf@plt>
lea    0x10(%rsp),%rbx
lea    0x50(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <libkeccak_unhex@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1080 <memcmp@plt>
test   %eax,%eax
jne    12b2 <test_hex+0x132>
lea    0xe46(%rip),%rdi
call   1050 <puts@plt>
lea    0xe13(%rip),%rdi
call   1060 <printf@plt>
lea    0x10(%rsp),%rbx
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <libkeccak_unhex@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1080 <memcmp@plt>
test   %eax,%eax
je     12c9 <test_hex+0x149>
lea    0xe09(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
ret
lea    0xdef(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
jmp    12c3 <test_hex+0x143>

LLVM IR (-O0):
@__const.test_hex.bindata = [8 x i8] c"\04/\12\83\FF\80\A3\00"
@__const.test_hex.hexdata_upper = [17 x i8] c"042F1283FF80A300\00"
@__const.test_hex.hexdata_lower = [17 x i8] c"042f1283ff80a300\00"
@.str = [32 x i8] c"Testing libkeccak_behex_lower: \00"
@.str.1 = [4 x i8] c"OK\0A\00"
@.str.2 = [6 x i8] c"Fail\0A\00"
@.str.3 = [32 x i8] c"Testing libkeccak_behex_upper: \00"
@.str.4 = [39 x i8] c"Testing libkeccak_unhex on uppercase: \00"
@.str.5 = [39 x i8] c"Testing libkeccak_unhex on lowercase: \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @test_hex() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [17 x i8]
%4 = alloca [17 x i8]
%5 = alloca [17 x i8]
%6 = bitcast [8 x i8]* %2 to i8*
%7 = bitcast [17 x i8]* %3 to i8*
%8 = bitcast [17 x i8]* %4 to i8*
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%12 = call i32 @libkeccak_behex_lower(i8* %10, i8* %11, i32 8)
%13 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%15 = call i32 @strcmp(i8* %13, i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %0
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %62
21: ; preds = %17
%22 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%25 = call i32 @libkeccak_behex_upper(i8* %23, i8* %24, i32 8)
%26 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%28 = call i32 @strcmp(i8* %26, i8* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %21
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %34
32: ; preds = %21
%33 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %62
34: ; preds = %30
%35 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%36 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%37 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%38 = call i32 @libkeccak_unhex(i8* %36, i8* %37)
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%41 = call i32 @memcmp(i8* %39, i8* %40, i32 8)
%42 = icmp ne i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %34
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %47
45: ; preds = %34
%46 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %62
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%49 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%50 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%51 = call i32 @libkeccak_unhex(i8* %49, i8* %50)
%52 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%53 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%54 = call i32 @memcmp(i8* %52, i8* %53, i32 8)
%55 = icmp ne i32 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %47
%57 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %60
58: ; preds = %47
%59 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %62
60: ; preds = %56
%61 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %62
62: ; preds = %60, %58, %45, %32, %19
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@__const.test_hex.hexdata_upper = [17 x i8] c"042F1283FF80A300\00"
@__const.test_hex.hexdata_lower = [17 x i8] c"042f1283ff80a300\00"
@.str = [32 x i8] c"Testing libkeccak_behex_lower: \00"
@.str.3 = [32 x i8] c"Testing libkeccak_behex_upper: \00"
@.str.4 = [39 x i8] c"Testing libkeccak_unhex on uppercase: \00"
@.str.5 = [39 x i8] c"Testing libkeccak_unhex on lowercase: \00"
@str.9 = [3 x i8] c"OK\00"
@str.13 = [5 x i8] c"Fail\00"
define i32 @test_hex() {
%1 = alloca i64
%2 = alloca [17 x i8]
%3 = alloca [17 x i8]
%4 = alloca [17 x i8]
%5 = bitcast i64* %1 to i8*
store i64 46022256107859716, i64* %1
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @libkeccak_behex_lower(i8* %8, i8* %5, i32 8)
%11 = call i32 @strcmp(i8* %8, i8* %7)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0))
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @libkeccak_behex_upper(i8* %8, i8* %5, i32 8)
%17 = call i32 @strcmp(i8* %8, i8* %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %27
19: ; preds = %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
br label %42
21: ; preds = %13
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0))
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @libkeccak_unhex(i8* %8, i8* %6)
%25 = call i32 @memcmp(i8* %5, i8* %8, i32 8)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %35
27: ; preds = %13
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
br label %42
29: ; preds = %21
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0))
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 @libkeccak_unhex(i8* %8, i8* %7)
%33 = call i32 @memcmp(i8* %5, i8* %8, i32 8)
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %40
35: ; preds = %21
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
br label %42
37: ; preds = %29
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0))
%39 = call i32 @putchar(i32 10)
br label %42
40: ; preds = %29
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0))
br label %42
42: ; preds = %37, %40, %35, %27, %19
%43 = phi i32 [ -1, %19 ], [ -1, %27 ], [ -1, %35 ], [ -1, %40 ], [ 0, %37 ]
ret i32 %43
}