#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 ChangePin(unsigned short ctn) {
  unsigned char change[11] = {0x00, 0x24, 0x00, 0x00, 0x06, 0x00,
                              0x00, 0x00, 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();
  change[5] = buffer[0];
  change[6] = buffer[1];
  change[7] = buffer[2];
  printf("New PIN (3 bytes): ");
  scanf("%X %X %X", (unsigned int *)buffer, (unsigned int *)(buffer + 1),
        (unsigned int *)(buffer + 2));
  dummy = getchar();
  change[8] = buffer[0];
  change[9] = buffer[1];
  change[10] = buffer[2];
  dad = 0;
  sad = 2;
  lr = 256;
  printf("Command: ");
  PrintArray(change, 11);
  ret = CT_data(ctn, &dad, &sad, 11, change, &lr, res);
  if (ret != 0) {
    fprintf(stderr, "Error on CHANGE VERIFICATION DATA: %d\n", ret);
    return;
  }
  printf("Response: ");
  PrintArray(res, lr);
}


x86 assembly (clang, -O0):
<ChangePin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe84(%rip),%ax
mov    %ax,-0x5(%rbp)
mov    0xe7c(%rip),%al
mov    %al,-0x3(%rbp)
lea    0xe80(%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    0xe53(%rip),%rdi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x138(%rbp)
mov    -0x30(%rbp),%al
mov    %al,-0x8(%rbp)
mov    -0x2f(%rbp),%al
mov    %al,-0x7(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x6(%rbp)
lea    0xe31(%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    0xe08(%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    0xde3(%rip),%rdi
call   1030 <printf@plt>
lea    -0xd(%rbp),%rdi
mov    $0xb,%esi
call   1060 <PrintArray@plt>
mov    -0x2(%rbp),%di
lea    -0xd(%rbp),%r8
lea    -0x130(%rbp),%rax
lea    -0x131(%rbp),%rsi
lea    -0x132(%rbp),%rdx
mov    $0xb,%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     12c4 <ChangePin+0x164>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
movsbl -0x139(%rbp),%edx
call   1050 <fprintf@plt>
jmp    12e3 <ChangePin+0x183>
lea    0xd8e(%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):
<ChangePin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x140,%rsp
mov    %edi,%r14d
movb   $0x6,0x18(%rsp)
movl   $0x2400,0x14(%rsp)
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
lea    0x21(%rsp),%r15
lea    0x22(%rsp),%r12
lea    0xe6f(%rip),%rbx
lea    0x20(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1070 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x20(%rsp),%al
mov    %al,0x19(%rsp)
movzwl 0x21(%rsp),%eax
mov    %ax,0x1a(%rsp)
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1070 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x20(%rsp),%al
mov    %al,0x1c(%rsp)
movzwl 0x21(%rsp),%eax
mov    %ax,0x1d(%rsp)
movb   $0x0,0x11(%rsp)
movb   $0x2,0x10(%rsp)
movw   $0x100,0x12(%rsp)
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xb,%esi
call   1060 <PrintArray@plt>
lea    0x40(%rsp),%rax
mov    %rax,(%rsp)
lea    0x11(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x12(%rsp),%r9
mov    %r14d,%edi
mov    $0xb,%ecx
mov    %rbx,%r8
call   1080 <CT_data@plt>
test   %al,%al
je     1276 <ChangePin+0x116>
mov    0x2d7d(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%edx
lea    0xdc3(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1291 <ChangePin+0x131>
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
movzwl 0x12(%rsp),%esi
lea    0x40(%rsp),%rdi
call   1060 <PrintArray@plt>
add    $0x140,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.ChangePin.change = [11 x i8] c"\00$\00\00\06\00\00\00\00\00\00"
@.str = [16 x i8] c"PIN (3 bytes): \00"
@.str.1 = [9 x i8] c"%X %X %X\00"
@.str.2 = [20 x i8] c"New PIN (3 bytes): \00"
@.str.3 = [10 x i8] c"Command: \00"
@stderr = global i32 0
@.str.4 = [39 x i8] c"Error on CHANGE VERIFICATION DATA: %d\0A\00"
@.str.5 = [11 x i8] c"Response: \00"
define void @ChangePin(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca [11 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 [11 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 [11 x i8], [11 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 [11 x i8], [11 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 [11 x i8], [11 x i8]* %3, i64 0, i64 7
store i8 %30, i8* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%34 = bitcast i8* %33 to i32*
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = bitcast i8* %36 to i32*
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = bitcast i8* %39 to i32*
%41 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %34, i32* %37, i32* %40)
%42 = call i32 (...) @getchar()
store i32 %42, i32* %9
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%44 = load i8, i8* %43
%45 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 8
store i8 %44, i8* %45
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 1
%47 = load i8, i8* %46
%48 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 9
store i8 %47, i8* %48
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 2
%50 = load i8, i8* %49
%51 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 %50, i8* %51
store i8 0, i8* %6
store i8 2, i8* %7
store i16 256, i16* %8
%52 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%53 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%54 = call i32 @PrintArray(i8* %53, i16 zeroext 11)
%55 = load i16, i16* %2
%56 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%58 = call signext i8 @CT_data(i16 zeroext %55, i8* %6, i8* %7, i32 11, i8* %56, i16* %8, i8* %57)
store i8 %58, i8* %10
%59 = load i8, i8* %10
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %1
%63 = load i32, i32* @stderr
%64 = load i8, i8* %10
%65 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8 signext %64)
br label %71
66: ; preds = %1
%67 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%69 = load i16, i16* %8
%70 = call i32 @PrintArray(i8* %68, i16 zeroext %69)
br label %71
71: ; preds = %66, %62
ret void
}

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