#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 INNO_UAM_Transfers(unsigned char *, int, unsigned char *, unsigned int *,
                       unsigned short *);
int /*<<< orphan*/ printf(char *);
int Card_ReadBin_2G(unsigned int offset, unsigned char dataLen,
                    unsigned char *lpRes, unsigned int *nResLen) {
  unsigned char cmd[8] = "\xA0\xB0\x00\x00\x00";
  unsigned int nStatus = 0;
  int ret = 0;
  printf("Card_ReadBin_2G\n");
  cmd[2] = (unsigned char)(offset >> 8);
  cmd[3] = (unsigned char)(offset);
  cmd[4] = (unsigned char)(dataLen);
  ret = INNO_UAM_Transfers(cmd, 5, lpRes, nResLen, (unsigned short *)&nStatus);
  if (ret < 0)
    goto err;
  if (dataLen != *nResLen)
    goto err;
  if (0x9000 != nStatus)
    goto err;
  return 0;
err:
  ret = -1;
  return ret;
}


x86 assembly (clang, -O0):
<Card_ReadBin_2G>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x26(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x25(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    $0x5,%esi
call   1040 <INNO_UAM_Transfers@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    119f <Card_ReadBin_2G+0x7f>
jmp    11d3 <Card_ReadBin_2G+0xb3>
movzbl -0x9(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
je     11b4 <Card_ReadBin_2G+0x94>
jmp    11d3 <Card_ReadBin_2G+0xb3>
mov    $0x9000,%eax
cmp    -0x2c(%rbp),%eax
je     11c7 <Card_ReadBin_2G+0xa7>
jmp    11d3 <Card_ReadBin_2G+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <Card_ReadBin_2G+0xc0>
movl   $0xffffffff,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Card_ReadBin_2G>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
movq   $0xb0a0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
mov    %bh,0x12(%rsp)
mov    %bl,0x13(%rsp)
mov    %bpl,0x14(%rsp)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%r8
mov    $0x5,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <INNO_UAM_Transfers@plt>
test   %eax,%eax
js     1191 <Card_ReadBin_2G+0x71>
movzbl %bpl,%eax
cmp    %eax,(%r15)
jne    1191 <Card_ReadBin_2G+0x71>
xor    %eax,%eax
cmpl   $0x9000,0xc(%rsp)
je     1196 <Card_ReadBin_2G+0x76>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.Card_ReadBin_2G.cmd = [8 x i8] c"\A0\B0\00\00\00\00\00\00"
@.str = [17 x i8] c"Card_ReadBin_2G\0A\00"
define i32 @Card_ReadBin_2G(i32 %0, i8 zeroext %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca [8 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%13 = bitcast [8 x i8]* %10 to i8*
store i32 0, i32* %11
store i32 0, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %6
%16 = lshr i32 %15, 8
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 2
store i8 %17, i8* %18
%19 = load i32, i32* %6
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 3
store i8 %20, i8* %21
%22 = load i8, i8* %7
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 4
store i8 %22, i8* %23
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%25 = load i8*, i8** %8
%26 = load i32*, i32** %9
%27 = bitcast i32* %11 to i16*
%28 = call i32 @INNO_UAM_Transfers(i8* %24, i32 5, i8* %25, i32* %26, i16* %27)
store i32 %28, i32* %12
%29 = load i32, i32* %12
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %4
br label %44
32: ; preds = %4
%33 = load i8, i8* %7
%34 = zext i8 %33 to i32
%35 = load i32*, i32** %9
%36 = load i32, i32* %35
%37 = icmp ne i32 %34, %36
br i1 %37, label %38, label %39
38: ; preds = %32
br label %44
39: ; preds = %32
%40 = load i32, i32* %11
%41 = icmp ne i32 36864, %40
br i1 %41, label %42, label %43
42: ; preds = %39
br label %44
43: ; preds = %39
store i32 0, i32* %5
br label %46
44: ; preds = %42, %38, %31
store i32 -1, i32* %12
%45 = load i32, i32* %12
store i32 %45, i32* %5
br label %46
46: ; preds = %44, %43
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
@str = [16 x i8] c"Card_ReadBin_2G\00"
define i32 @Card_ReadBin_2G(i32 %0, i8 zeroext %1, i8* %2, i32* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to [8 x i8]*
%7 = alloca i32
%8 = bitcast i64* %5 to i8*
store i64 45216, i64* %5
%9 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%11 = lshr i32 %0, 8
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
store i8 %12, i8* %13
%14 = trunc i32 %0 to i8
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 3
store i8 %14, i8* %15
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
store i8 %1, i8* %16
%17 = bitcast i32* %7 to i16*
%18 = call i32 @INNO_UAM_Transfers(i8* %8, i32 5, i8* %2, i32* %3, i16* %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %4
%21 = zext i8 %1 to i32
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, %21
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 36864
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %28
27: ; preds = %20, %4
br label %28
28: ; preds = %20, %27
%29 = phi i32 [ -1, %27 ], [ 0, %20 ]
ret i32 %29
}