#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*/ memcpy(unsigned char *, unsigned char *, int);
unsigned short multosSendAPDU(int, int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int, int /*<<< orphan*/, unsigned char *, int,
                              unsigned char *, int);
int openMelApp(unsigned char *alc) {
  unsigned char data[255];
  unsigned char La;
  unsigned short SW;
  unsigned short offset = 26;
  memcpy(data, alc + offset, 126);
  offset = offset + 126;
  data[126] = 0;
  data[127] = 128;
  data[128] = 0;
  data[129] = 128;
  memcpy(data + 130, alc + offset, 4);
  offset = offset + 4;
  memcpy(data + 134, alc + offset + 3, 23);
  SW = multosSendAPDU(190, 18, 0, 0, 157, 0, &La, 1, data, 10000);
  if (SW == 0x9000 || ((SW >> 8) == 0x61))
    return (1);
  else
    return (0);
}


x86 assembly (clang, -O0):
<openMelApp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
movw   $0x1a,-0x116(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movzwl -0x116(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x7e,%edx
call   1040 <memcpy@plt>
movzwl -0x116(%rbp),%eax
add    $0x7e,%eax
mov    %ax,-0x116(%rbp)
movb   $0x0,-0x92(%rbp)
movb   $0x80,-0x91(%rbp)
movb   $0x0,-0x90(%rbp)
movb   $0x80,-0x8f(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x82,%rdi
mov    -0x10(%rbp),%rsi
movzwl -0x116(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movzwl -0x116(%rbp),%eax
add    $0x4,%eax
mov    %ax,-0x116(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x86,%rdi
mov    -0x10(%rbp),%rsi
movzwl -0x116(%rbp),%eax
cltq
add    %rax,%rsi
add    $0x3,%rsi
mov    $0x17,%edx
call   1040 <memcpy@plt>
lea    -0x110(%rbp),%rax
mov    $0xbe,%edi
mov    $0x12,%esi
xor    %r9d,%r9d
mov    $0x9d,%r8d
lea    -0x111(%rbp),%r10
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r10,(%rsp)
movl   $0x1,0x8(%rsp)
mov    %rax,0x10(%rsp)
movl   $0x2710,0x18(%rsp)
call   1030 <multosSendAPDU@plt>
mov    %ax,-0x114(%rbp)
movzwl -0x114(%rbp),%eax
cmp    $0x9000,%eax
je     125c <openMelApp+0x13c>
movzwl -0x114(%rbp),%eax
sar    $0x8,%eax
cmp    $0x61,%eax
jne    1268 <openMelApp+0x148>
movl   $0x1,-0x4(%rbp)
jmp    126f <openMelApp+0x14f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openMelApp>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbx
lea    0x1a(%rdi),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x7e,%edx
call   1040 <memcpy@plt>
movl   $0x80008000,0x8e(%rsp)
lea    0x92(%rsp),%rdi
lea    0x98(%rbx),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x96(%rsp),%rdi
add    $0x9f,%rbx
mov    %rbx,%rsi
mov    $0x17,%edx
call   1040 <memcpy@plt>
lea    0xf(%rsp),%rax
mov    $0xbe,%edi
mov    $0x12,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x9d,%r8d
xor    %r9d,%r9d
push   $0x2710
push   %r14
push   $0x1
push   %rax
call   1030 <multosSendAPDU@plt>
add    $0x20,%rsp
movzwl %ax,%ecx
cmp    $0x9000,%ecx
sete   %cl
and    $0xff00,%eax
cmp    $0x6100,%eax
sete   %al
or     %cl,%al
movzbl %al,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @openMelApp(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [255 x i8]
%5 = alloca i8
%6 = alloca i16
%7 = alloca i16
store i8* %0, i8** %3
store i16 26, i16* %7
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = load i16, i16* %7
%11 = zext i16 %10 to i32
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = call i32 @memcpy(i8* %8, i8* %13, i32 126)
%15 = load i16, i16* %7
%16 = zext i16 %15 to i32
%17 = add nsw i32 %16, 126
%18 = trunc i32 %17 to i16
store i16 %18, i16* %7
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 126
store i8 0, i8* %19
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 127
store i8 -128, i8* %20
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 128
store i8 0, i8* %21
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 129
store i8 -128, i8* %22
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 130
%25 = load i8*, i8** %3
%26 = load i16, i16* %7
%27 = zext i16 %26 to i32
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = call i32 @memcpy(i8* %24, i8* %29, i32 4)
%31 = load i16, i16* %7
%32 = zext i16 %31 to i32
%33 = add nsw i32 %32, 4
%34 = trunc i32 %33 to i16
store i16 %34, i16* %7
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 134
%37 = load i8*, i8** %3
%38 = load i16, i16* %7
%39 = zext i16 %38 to i32
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 3
%43 = call i32 @memcpy(i8* %36, i8* %42, i32 23)
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%45 = call zeroext i16 @multosSendAPDU(i32 190, i32 18, i32 0, i32 0, i32 157, i32 0, i8* %5, i32 1, i8* %44, i32 10000)
store i16 %45, i16* %6
%46 = load i16, i16* %6
%47 = zext i16 %46 to i32
%48 = icmp eq i32 %47, 36864
br i1 %48, label %54, label %49
49: ; preds = %1
%50 = load i16, i16* %6
%51 = zext i16 %50 to i32
%52 = ashr i32 %51, 8
%53 = icmp eq i32 %52, 97
br i1 %53, label %54, label %55
54: ; preds = %49, %1
store i32 1, i32* %2
br label %56
55: ; preds = %49
store i32 0, i32* %2
br label %56
56: ; preds = %55, %54
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @openMelApp(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds i8, i8* %0, i64 26
%6 = call i32 @memcpy(i8* %4, i8* %5, i32 126)
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 126
store i8 0, i8* %7
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 127
store i8 -128, i8* %8
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 128
store i8 0, i8* %9
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 129
store i8 -128, i8* %10
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 130
%12 = getelementptr inbounds i8, i8* %0, i64 152
%13 = call i32 @memcpy(i8* %11, i8* %12, i32 4)
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 134
%15 = getelementptr inbounds i8, i8* %0, i64 159
%16 = call i32 @memcpy(i8* %14, i8* %15, i32 23)
%17 = call zeroext i16 @multosSendAPDU(i32 190, i32 18, i32 0, i32 0, i32 157, i32 0, i8* %3, i32 1, i8* %4, i32 10000)
%18 = icmp eq i16 %17, -28672
%19 = and i16 %17, -256
%20 = icmp eq i16 %19, 24832
%21 = or i1 %18, %20
%22 = zext i1 %21 to i32
ret i32 %22
}