#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*/ FILE;
typedef int /*<<< orphan*/ DES_key_schedule;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_cryptogram(char *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *, int);
int /*<<< orphan*/ get_encks_der_file(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ make_session_key(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    char *, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_hex(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fd;
  char ccrgram[8];
  char hcrgram[8];
  char derdat[(8 * 2)] = {0};
  DES_key_schedule enc1, enc2;
  DES_key_schedule s_enc1, s_enc2;
  if (argc < 2) {
    printf("Usage: ./%s <filename>\n", argv[0]);
    printf("Put HC, CC, S ENC key, S MAC key to the file.\n");
    printf("Bytes have to be seperated by white space.\n");
    return 1;
  }
  fd = fopen(argv[1], "r");
  if (fd == NULL) {
    perror("fopen");
    return 1;
  }
  get_encks_der_file(fd, &enc1, &enc2, derdat);
  fclose(fd);
  make_session_key(&enc1, &enc2, derdat, &s_enc1, &s_enc2);
  get_cryptogram(ccrgram, &s_enc1, &s_enc2, 0);
  get_cryptogram(hcrgram, &s_enc1, &s_enc2, 1);
  print_hex("Card Cryptogram", ccrgram, 8);
  print_hex("Host Cryptogram", hcrgram, 8);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11fd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c9 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1238 <main+0xa8>
lea    0xe4e(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c9 <main+0x139>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1070 <get_encks_der_file@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x40(%rbp),%rdx
lea    -0x44(%rbp),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rcx
lea    -0x50(%rbp),%r8
call   1090 <make_session_key@plt>
lea    -0x20(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <get_cryptogram@plt>
lea    -0x28(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x1,%ecx
call   1030 <get_cryptogram@plt>
lea    -0x20(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x8,%edx
call   1080 <print_hex@plt>
lea    -0x28(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x8,%edx
call   1080 <print_hex@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
cmp    $0x1,%edi
jg     11de <main+0x4e>
mov    (%rsi),%rsi
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    1295 <main+0x105>
mov    0x8(%rsi),%rdi
lea    0xe2f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a6 <main+0x116>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1070 <get_encks_der_file@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x4(%rsp),%r13
mov    %rsp,%rbp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1090 <make_session_key@plt>
lea    0x30(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1030 <get_cryptogram@plt>
lea    0x28(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    $0x1,%ecx
call   1030 <get_cryptogram@plt>
lea    0xdac(%rip),%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1080 <print_hex@plt>
lea    0xda8(%rip),%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1080 <print_hex@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%ebx
jmp    1295 <main+0x105>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: ./%s <filename>\0A\00"
@.str.1 = [47 x i8] c"Put HC, CC, S ENC key, S MAC key to the file.\0A\00"
@.str.2 = [44 x i8] c"Bytes have to be seperated by white space.\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"fopen\00"
@.str.5 = [16 x i8] c"Card Cryptogram\00"
@.str.6 = [16 x i8] c"Host Cryptogram\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [8 x i8]
%8 = alloca [8 x i8]
%9 = alloca [16 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [16 x i8]* %9 to i8*
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %49
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %49
33: ; preds = %24
%34 = load i32*, i32** %6
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%36 = call i32 @get_encks_der_file(i32* %34, i32* %10, i32* %11, i8* %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%40 = call i32 @make_session_key(i32* %10, i32* %11, i8* %39, i32* %12, i32* %13)
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%42 = call i32 @get_cryptogram(i8* %41, i32* %12, i32* %13, i32 0)
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%44 = call i32 @get_cryptogram(i8* %43, i32* %12, i32* %13, i32 1)
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%46 = call i32 @print_hex(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %45, i32 8)
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%48 = call i32 @print_hex(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %47, i32 8)
store i32 0, i32* %3
br label %49
49: ; preds = %33, %31, %17
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage: ./%s <filename>\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"fopen\00"
@.str.5 = [16 x i8] c"Card Cryptogram\00"
@.str.6 = [16 x i8] c"Host Cryptogram\00"
@str = [46 x i8] c"Put HC, CC, S ENC key, S MAC key to the file.\00"
@str.7 = [43 x i8] c"Bytes have to be seperated by white space.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8 x i8]
%4 = alloca [8 x i8]
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%13 = bitcast i32* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = icmp slt i32 %0, 2
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8*, i8** %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.7, i64 0, i64 0))
br label %38
23: ; preds = %2
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %38
30: ; preds = %23
%31 = call i32 @get_encks_der_file(i32* %26, i32* %6, i32* %7, i8* %12)
%32 = call i32 @fclose(i32* %26)
%33 = call i32 @make_session_key(i32* %6, i32* %7, i8* %12, i32* %8, i32* %9)
%34 = call i32 @get_cryptogram(i8* %10, i32* %8, i32* %9, i32 0)
%35 = call i32 @get_cryptogram(i8* %11, i32* %8, i32* %9, i32 1)
%36 = call i32 @print_hex(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 8)
%37 = call i32 @print_hex(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %11, i32 8)
br label %38
38: ; preds = %30, %28, %18
%39 = phi i32 [ 1, %18 ], [ 1, %28 ], [ 0, %30 ]
ret i32 %39
}