#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 /*<<< orphan*/ hmsg;
typedef int /*<<< orphan*/ cmsg;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ ciphersaber_2_dec(unsigned char *, unsigned char *, int,
                                     char *, int);
int hex2raw(char const *, unsigned char *);
int /*<<< orphan*/ memcmp(unsigned char *, char *, int);
void ciphersaber_2_test() {
  const char hmsg[] = "ba9ab4cffb7700e618e382e8fcc5ab9813b1abc436ba7d5cdea1a31f"
                      "b72fb5763c44cfc2ac77afee19ad";
  unsigned char cmsg[(sizeof(hmsg) - 1) / 2];
  assert(hex2raw(hmsg, cmsg) == sizeof cmsg);
  unsigned char plainmsg[sizeof(cmsg) - 10];
  ciphersaber_2_dec(plainmsg, cmsg, sizeof(cmsg), "asdfg", 10);
  assert(!memcmp(plainmsg, "This is a test of CipherSaber-2.",
                 sizeof("This is a test of CipherSaber-2.") - 1));
}


x86 assembly (clang, -O0):
<ciphersaber_2_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0x60(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x55,%edx
call   1070 <memcpy@plt>
lea    -0x60(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1040 <hex2raw@plt>
cltq
cmp    $0x2a,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x2a,%edx
lea    0xea8(%rip),%rcx
mov    $0xa,%r8d
call   1030 <ciphersaber_2_dec@plt>
lea    -0xb0(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x20,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ciphersaber_2_test>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
movaps 0xeef(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x64613931656566,%rax
mov    %rax,0x4d(%rsp)
mov    %rsp,%rdi
lea    0x80(%rsp),%r14
mov    %r14,%rsi
call   1040 <hex2raw@plt>
xor    %edi,%edi
cmp    $0x2a,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xe99(%rip),%rcx
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2a,%edx
mov    $0xa,%r8d
call   1030 <ciphersaber_2_dec@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
mov    $0x20,%edx
call   1050 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.ciphersaber_2_test.hmsg = [85 x i8] c"ba9ab4cffb7700e618e382e8fcc5ab9813b1abc436ba7d5cdea1a31fb72fb5763c44cfc2ac77afee19ad\00"
@.str = [6 x i8] c"asdfg\00"
@.str.1 = [33 x i8] c"This is a test of CipherSaber-2.\00"
define void @ciphersaber_2_test() {
%1 = alloca [85 x i8]
%2 = alloca [42 x i8]
%3 = alloca [32 x i8]
%4 = bitcast [85 x i8]* %1 to i8*
%5 = getelementptr inbounds [85 x i8], [85 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [42 x i8], [42 x i8]* %2, i64 0, i64 0
%7 = call i32 @hex2raw(i8* %5, i8* %6)
%8 = sext i32 %7 to i64
%9 = icmp eq i64 %8, 42
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [42 x i8], [42 x i8]* %2, i64 0, i64 0
%14 = call i32 @ciphersaber_2_dec(i8* %12, i8* %13, i32 42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 10)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%16 = call i32 @memcmp(i8* %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 32)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
ret void
}

LLVM IR (-O2):
@__const.ciphersaber_2_test.hmsg = [85 x i8] c"ba9ab4cffb7700e618e382e8fcc5ab9813b1abc436ba7d5cdea1a31fb72fb5763c44cfc2ac77afee19ad\00"
@.str = [6 x i8] c"asdfg\00"
@.str.1 = [33 x i8] c"This is a test of CipherSaber-2.\00"
define void @ciphersaber_2_test() {
%1 = alloca [85 x i8]
%2 = alloca [42 x i8]
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [85 x i8], [85 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [42 x i8], [42 x i8]* %2, i64 0, i64 0
%6 = call i32 @hex2raw(i8* %4, i8* %5)
%7 = icmp eq i32 %6, 42
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%11 = call i32 @ciphersaber_2_dec(i8* %10, i8* %5, i32 42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 10)
%12 = call i32 @memcmp(i8* %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 32)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
ret void
}