#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 */
char CT_data(unsigned short, unsigned char *, unsigned char *, int,
             unsigned char *, unsigned short *, unsigned char *);
int /*<<< orphan*/ PrintArray(unsigned char *, unsigned short);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, unsigned int *, unsigned int *,
                         unsigned int *);
int /*<<< orphan*/ stderr;
void EnterPin(unsigned short ctn) {
  unsigned char verify[8] = {0x00, 0x20, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00};
  unsigned char buffer[32];
  unsigned char res[256];
  unsigned char dad;
  unsigned char sad;
  unsigned short lr;
  int dummy;
  char ret;
  printf("PIN (3 bytes): ");
  scanf("%X %X %X", (unsigned int *)buffer, (unsigned int *)(buffer + 1),
        (unsigned int *)(buffer + 2));
  dummy = getchar();
  verify[5] = buffer[0];
  verify[6] = buffer[1];
  verify[7] = buffer[2];
  dad = 0;
  sad = 2;
  lr = 256;
  printf("Command: ");
  PrintArray(verify, 8);
  ret = CT_data(ctn, &dad, &sad, 8, verify, &lr, res);
  if (ret != 0) {
    fprintf(stderr, "Error on VERIFY: %d\n", ret);
    return;
  }
  printf("Response: ");
  PrintArray(res, lr);
}


x86 assembly (clang, -O0):
<EnterPin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0xa(%rbp)
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x1,%rdx
lea    -0x30(%rbp),%rcx
add    $0x2,%rcx
lea    0xe74(%rip),%rdi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x138(%rbp)
mov    -0x30(%rbp),%al
mov    %al,-0x5(%rbp)
mov    -0x2f(%rbp),%al
mov    %al,-0x4(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x3(%rbp)
movb   $0x0,-0x131(%rbp)
movb   $0x2,-0x132(%rbp)
movw   $0x100,-0x134(%rbp)
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
lea    -0xa(%rbp),%rdi
mov    $0x8,%esi
call   1060 <PrintArray@plt>
mov    -0x2(%rbp),%di
lea    -0xa(%rbp),%r8
lea    -0x130(%rbp),%rax
lea    -0x131(%rbp),%rsi
lea    -0x132(%rbp),%rdx
mov    $0x8,%ecx
lea    -0x134(%rbp),%r9
movzwl %di,%edi
mov    %rax,(%rsp)
call   1080 <CT_data@plt>
mov    %al,-0x139(%rbp)
movsbl -0x139(%rbp),%eax
cmp    $0x0,%eax
je     1265 <EnterPin+0x105>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
movsbl -0x139(%rbp),%edx
call   1050 <fprintf@plt>
jmp    1284 <EnterPin+0x124>
lea    0xdd4(%rip),%rdi
call   1030 <printf@plt>
lea    -0x130(%rbp),%rdi
movzwl -0x134(%rbp),%esi
call   1060 <PrintArray@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnterPin>:
push   %rbp
push   %rbx
sub    $0x148,%rsp
mov    %edi,%ebp
movabs $0x300002000,%rax
mov    %rax,0x18(%rsp)
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
lea    0x21(%rsp),%rdx
lea    0x22(%rsp),%rcx
lea    0xe79(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1070 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x20(%rsp),%al
mov    %al,0x1d(%rsp)
movzwl 0x21(%rsp),%eax
mov    %ax,0x1e(%rsp)
movb   $0x0,0x15(%rsp)
movb   $0x2,0x14(%rsp)
movw   $0x100,0x16(%rsp)
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <PrintArray@plt>
lea    0x40(%rsp),%rax
mov    %rax,(%rsp)
lea    0x15(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x16(%rsp),%r9
mov    %ebp,%edi
mov    $0x8,%ecx
mov    %rbx,%r8
call   1080 <CT_data@plt>
test   %al,%al
je     122e <EnterPin+0xce>
mov    0x2dc5(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%edx
lea    0xdfc(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1249 <EnterPin+0xe9>
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
movzwl 0x16(%rsp),%esi
lea    0x40(%rsp),%rdi
call   1060 <PrintArray@plt>
add    $0x148,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.EnterPin.verify = [8 x i8] c"\00 \00\00\03\00\00\00"
@.str = [16 x i8] c"PIN (3 bytes): \00"
@.str.1 = [9 x i8] c"%X %X %X\00"
@.str.2 = [10 x i8] c"Command: \00"
@stderr = global i32 0
@.str.3 = [21 x i8] c"Error on VERIFY: %d\0A\00"
@.str.4 = [11 x i8] c"Response: \00"
define void @EnterPin(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca [8 x i8]
%4 = alloca [32 x i8]
%5 = alloca [256 x i8]
%6 = alloca i8
%7 = alloca i8
%8 = alloca i16
%9 = alloca i32
%10 = alloca i8
store i16 %0, i16* %2
%11 = bitcast [8 x i8]* %3 to i8*
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%14 = bitcast i8* %13 to i32*
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = bitcast i8* %16 to i32*
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = bitcast i8* %19 to i32*
%21 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %14, i32* %17, i32* %20)
%22 = call i32 (...) @getchar()
store i32 %22, i32* %9
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%24 = load i8, i8* %23
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
store i8 %24, i8* %25
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 1
%27 = load i8, i8* %26
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
store i8 %27, i8* %28
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 2
%30 = load i8, i8* %29
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
store i8 %30, i8* %31
store i8 0, i8* %6
store i8 2, i8* %7
store i16 256, i16* %8
%32 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%34 = call i32 @PrintArray(i8* %33, i16 zeroext 8)
%35 = load i16, i16* %2
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%38 = call signext i8 @CT_data(i16 zeroext %35, i8* %6, i8* %7, i32 8, i8* %36, i16* %8, i8* %37)
store i8 %38, i8* %10
%39 = load i8, i8* %10
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %1
%43 = load i32, i32* @stderr
%44 = load i8, i8* %10
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8 signext %44)
br label %51
46: ; preds = %1
%47 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%49 = load i16, i16* %8
%50 = call i32 @PrintArray(i8* %48, i16 zeroext %49)
br label %51
51: ; preds = %46, %42
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"PIN (3 bytes): \00"
@.str.1 = [9 x i8] c"%X %X %X\00"
@.str.2 = [10 x i8] c"Command: \00"
@stderr = global i32 0
@.str.3 = [21 x i8] c"Error on VERIFY: %d\0A\00"
@.str.4 = [11 x i8] c"Response: \00"
define void @EnterPin(i16 zeroext %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to [8 x i8]*
%4 = alloca [32 x i8]
%5 = alloca [256 x i8]
%6 = alloca i8
%7 = alloca i8
%8 = alloca i16
%9 = bitcast i64* %2 to i8*
store i64 12884910080, i64* %2
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = bitcast i16* %8 to i8*
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = bitcast [32 x i8]* %4 to i32*
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 1
%16 = bitcast i8* %15 to i32*
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 2
%18 = bitcast i8* %17 to i32*
%19 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %14, i32* %16, i32* %18)
%20 = call i32 (...) @getchar()
%21 = load i8, i8* %10
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
store i8 %21, i8* %22
%23 = load i8, i8* %15
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
store i8 %23, i8* %24
%25 = load i8, i8* %17
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
store i8 %25, i8* %26
store i8 0, i8* %6
store i8 2, i8* %7
store i16 256, i16* %8
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @PrintArray(i8* %9, i16 zeroext 8)
%29 = call signext i8 @CT_data(i16 zeroext %0, i8* %6, i8* %7, i32 8, i8* %9, i16* %8, i8* %11)
%30 = icmp eq i8 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %1
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8 signext %29)
br label %38
34: ; preds = %1
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%36 = load i16, i16* %8
%37 = call i32 @PrintArray(i8* %11, i16 zeroext %36)
br label %38
38: ; preds = %34, %31
ret void
}