#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*/ des_crypt(int /*<<< orphan*/, char *, int, char *, int,
                             char *, char const *, char *);
int /*<<< orphan*/ print_data(char *, char *, int);
int /*<<< orphan*/ printf(char *);
void DES_demo() {
  int i;
  char out[16] = {0};
  char in[16] = "Single block msg";
  const char key[24] = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b"
                       "\x51\x2e\x03\xd5\x34\x12\x00\x06"
                       "\xa0\x53\x07\x1e\x22\x00\x96\x77";
  char iv[8] = "\x3d\xaf\xba\x42\x9d\x9e\xb4\x30";
  printf(
      "\n+---------------------------------------------------------------+\n");
  printf("|  DES ECB mode encrypt/descrpt demo                            |\n");
  printf("+---------------------------------------------------------------+\n");
  des_crypt(0, "ecb(des)", 1, in, 16, out, key, iv);
  printf("\nDES encrypt result =>\n");
  print_data("IN", in, 16);
  print_data("OUT", out, 16);
  des_crypt(0, "ecb(des)", 0, out, 16, in, key, iv);
  printf("\nDES descrypt result =>\n");
  print_data("IN", out, 16);
  print_data("OUT", in, 16);
}


x86 assembly (clang, -O0):
<DES_demo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0xea1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe92(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rcx
lea    -0x20(%rbp),%r9
lea    -0x50(%rbp),%r10
lea    -0x58(%rbp),%rax
xor    %edi,%edi
lea    0xee0(%rip),%rsi
mov    $0x1,%edx
mov    $0x10,%r8d
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <des_crypt@plt>
lea    0xec9(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xed1(%rip),%rdi
mov    $0x10,%edx
call   1060 <print_data@plt>
lea    -0x20(%rbp),%rsi
lea    0xebf(%rip),%rdi
mov    $0x10,%edx
call   1060 <print_data@plt>
lea    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%r9
lea    -0x50(%rbp),%r10
lea    -0x58(%rbp),%rax
xor    %edx,%edx
lea    0xe78(%rip),%rsi
mov    $0x10,%r8d
mov    %edx,%edi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <des_crypt@plt>
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x10,%edx
call   1060 <print_data@plt>
lea    -0x30(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x10,%edx
call   1060 <print_data@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DES_demo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x779600221e0753a0,%rax
mov    %rax,0x20(%rsp)
movabs $0x30b49e9d42baaf3d,%rax
9e b4 30
mov    %rax,0x8(%rsp)
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
lea    0xeec(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbp
lea    0x10(%rsp),%rax
lea    0xe77(%rip),%r15
lea    0x30(%rsp),%r14
lea    0x40(%rsp),%rbx
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
mov    $0x10,%r8d
mov    %rbx,%r9
push   %rbp
push   %rax
call   1030 <des_crypt@plt>
add    $0x10,%rsp
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
lea    0xe42(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <print_data@plt>
lea    0xe2e(%rip),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <print_data@plt>
xor    %edi,%edi
mov    %r15,%rsi
xor    %edx,%edx
mov    %rbx,%rcx
mov    $0x10,%r8d
mov    %r14,%r9
push   %rbp
lea    0x18(%rsp),%rax
push   %rax
call   1030 <des_crypt@plt>
add    $0x10,%rsp
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <print_data@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <print_data@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.DES_demo.in = [16 x i8] c"Single block msg"
@__const.DES_demo.key = [24 x i8] c"\06\A9!@6\B8\A1[Q.\03\D54\12\00\06\A0S\07\1E\22\00\96w"
@__const.DES_demo.iv = [8 x i8] c"=\AF\BAB\9D\9E\B40"
@.str = [68 x i8] c"\0A+---------------------------------------------------------------+\0A\00"
@.str.1 = [67 x i8] c"| DES ECB mode encrypt/descrpt demo |\0A\00"
@.str.2 = [67 x i8] c"+---------------------------------------------------------------+\0A\00"
@.str.3 = [9 x i8] c"ecb(des)\00"
@.str.4 = [24 x i8] c"\0ADES encrypt result =>\0A\00"
@.str.5 = [3 x i8] c"IN\00"
@.str.6 = [4 x i8] c"OUT\00"
@.str.7 = [25 x i8] c"\0ADES descrypt result =>\0A\00"
define void @DES_demo() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [16 x i8]
%4 = alloca [24 x i8]
%5 = alloca [8 x i8]
%6 = bitcast [16 x i8]* %2 to i8*
%7 = bitcast [16 x i8]* %3 to i8*
%8 = bitcast [24 x i8]* %4 to i8*
%9 = bitcast [8 x i8]* %5 to i8*
%10 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [24 x i8], [24 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%17 = call i32 @des_crypt(i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 1, i8* %13, i32 16, i8* %14, i8* %15, i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%20 = call i32 @print_data(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %19, i32 16)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%22 = call i32 @print_data(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %21, i32 16)
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [24 x i8], [24 x i8]* %4, i64 0, i64 0
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%27 = call i32 @des_crypt(i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* %23, i32 16, i8* %24, i8* %25, i8* %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%30 = call i32 @print_data(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %29, i32 16)
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%32 = call i32 @print_data(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %31, i32 16)
ret void
}

LLVM IR (-O2):
@__const.DES_demo.in = [16 x i8] c"Single block msg"
@__const.DES_demo.key = [24 x i8] c"\06\A9!@6\B8\A1[Q.\03\D54\12\00\06\A0S\07\1E\22\00\96w"
@.str.3 = [9 x i8] c"ecb(des)\00"
@.str.5 = [3 x i8] c"IN\00"
@.str.6 = [4 x i8] c"OUT\00"
@str = [67 x i8] c"\0A+---------------------------------------------------------------+\00"
@str.8 = [66 x i8] c"| DES ECB mode encrypt/descrpt demo |\00"
@str.9 = [66 x i8] c"+---------------------------------------------------------------+\00"
@str.10 = [23 x i8] c"\0ADES encrypt result =>\00"
@str.11 = [24 x i8] c"\0ADES descrypt result =>\00"
define void @DES_demo() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = alloca [24 x i8]
%4 = alloca i64
%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 [24 x i8], [24 x i8]* %3, i64 0, i64 0
%8 = bitcast i64* %4 to i8*
store i64 3509604407895043901, i64* %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.9, i64 0, i64 0))
%12 = call i32 @des_crypt(i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 1, i8* %6, i32 16, i8* %5, i8* %7, i8* %8)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%14 = call i32 @print_data(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 16)
%15 = call i32 @print_data(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %5, i32 16)
%16 = call i32 @des_crypt(i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* %5, i32 16, i8* %6, i8* %7, i8* %8)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%18 = call i32 @print_data(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %5, i32 16)
%19 = call i32 @print_data(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %6, i32 16)
ret void
}