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

/* Variables and functions */
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ serpent_encrypt(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *);
int main() {
  uint32_t SK[32];
  unsigned char out[16];
  unsigned char correct[16] = {0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84,
                               0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84};
  unsigned char plain[16] = {0xBE, 0xB6, 0xC0, 0x69, 0x39, 0x38, 0x22, 0xD3,
                             0xBE, 0x73, 0xFF, 0x30, 0x52, 0x5E, 0xC4, 0x3E};
  unsigned char key[16] = {0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
                           0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48};
  serpent_encrypt((uint32_t *)key, (uint32_t *)plain, (uint32_t *)out);
  if (memcmp(out, correct, 16) == 0)
    printf("OK\n");
  else
    printf("ERROR\n");
  for (int i = 0; i < 16; i++) {
    printf("%x", out[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0xeb1(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0xb8(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0xd0(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0xc8(%rbp)
lea    -0xd0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
call   1040 <serpent_encrypt@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    11e5 <main+0xb5>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f3 <main+0xc3>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x10,-0xd4(%rbp)
jge    123b <main+0x10b>
movslq -0xd4(%rbp),%rax
movzbl -0xa0(%rbp,%rax,1),%esi
ff
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    11fd <main+0xcd>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
call   1050 <serpent_encrypt@plt>
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
lea    0xe9f(%rip),%rax
lea    0xe92(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
movzbl (%rsp),%esi
lea    0xe7b(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x2(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x3(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x5(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x6(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x7(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xd(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xe(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0xf(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.correct = [16 x i8] c"\EA\02G\14\AD\\M\84\EA\02G\14\AD\\M\84"
@__const.main.plain = [16 x i8] c"\BE\B6\C0i98\22\D3\BEs\FF0R^\C4>"
@__const.main.key = [16 x i8] c"+\D6E\9F\82\C5\B3\00\95,I\10H\81\FFH"
@.str = [4 x i8] c"OK\0A\00"
@.str.1 = [7 x i8] c"ERROR\0A\00"
@.str.2 = [3 x i8] c"%x\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i32]
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [16 x i8]* %4 to i8*
%9 = bitcast [16 x i8]* %5 to i8*
%10 = bitcast [16 x i8]* %6 to i8*
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%12 = bitcast i8* %11 to i32*
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%14 = bitcast i8* %13 to i32*
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%16 = bitcast i8* %15 to i32*
%17 = call i32 @serpent_encrypt(i32* %12, i32* %14, i32* %16)
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%20 = call i64 @memcmp(i8* %18, i8* %19, i32 16)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %26
24: ; preds = %0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
store i32 0, i32* %7
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 16
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %27
40: ; preds = %27
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@__const.main.correct = [16 x i8] c"\EA\02G\14\AD\\M\84\EA\02G\14\AD\\M\84"
@__const.main.plain = [16 x i8] c"\BE\B6\C0i98\22\D3\BEs\FF0R^\C4>"
@__const.main.key = [16 x i8] c"+\D6E\9F\82\C5\B3\00\95,I\10H\81\FFH"
@.str.2 = [3 x i8] c"%x\00"
@str = [6 x i8] c"ERROR\00"
@str.3 = [3 x i8] c"OK\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = bitcast [16 x i8]* %4 to i32*
%10 = bitcast [16 x i8]* %3 to i32*
%11 = bitcast [16 x i8]* %1 to i32*
%12 = call i32 @serpent_encrypt(i32* %9, i32* %10, i32* %11)
%13 = call i64 @memcmp(i8* %5, i8* %6, i32 16)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0)
%16 = call i32 @puts(i8* dereferenceable(1) %15)
%17 = load i8, i8* %5
%18 = zext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 3
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 4
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 5
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 6
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 7
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 8
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 9
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 10
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 11
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 12
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 13
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 14
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %74)
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 15
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %78)
ret i32 0
}