int MBBMS_TEL_GetSDVersion_2G(void) {
  unsigned char res[256];
  unsigned int resLen = 0;
  unsigned int fileSize = 0;
  unsigned int recordLen = 0;
  unsigned int i;
  int ret = 0;
  printf("MBBMS_TEL_GetSDVersion_2G\n");
  unsigned char cmd[7] = "\x3F\x00\x9F\x01";
  ret = Card_SelectFile_2G(cmd, 4, &fileSize, &recordLen);
  if (ret < 0) {
    printf("Card_SelectFile_2G fail  \n");
    goto err;
  }
  if (fileSize != 4) {
    goto err;
  }
  resLen = 256;
  ret = Card_ReadBin_2G(0, (unsigned char)fileSize, res, &resLen);
  if (ret < 0) {
    printf("Card_ReadBin_2G fail  \n");
    goto err;
  }
  printf("%s: res:\n", __func__);
  dump_mem(res, resLen);
  return ret;
err:
  ret = -1;
  return 0;
}


x86 assembly (clang, -O0):
<MBBMS_TEL_GetSDVersion_2G>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x124(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0xeeb(%rip),%eax
mov    %eax,-0x12b(%rbp)
mov    0xee2(%rip),%ax
mov    %ax,-0x127(%rbp)
mov    0xed7(%rip),%al
mov    %al,-0x125(%rbp)
lea    -0x12b(%rbp),%rdi
mov    $0x4,%esi
lea    -0x118(%rbp),%rdx
lea    -0x11c(%rbp),%rcx
mov    $0x0,%al
call   1060 <Card_SelectFile_2G@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jge    11ee <MBBMS_TEL_GetSDVersion_2G+0xae>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1287 <MBBMS_TEL_GetSDVersion_2G+0x147>
cmpl   $0x4,-0x118(%rbp)
je     1200 <MBBMS_TEL_GetSDVersion_2G+0xc0>
jmp    1287 <MBBMS_TEL_GetSDVersion_2G+0x147>
movl   $0x100,-0x114(%rbp)
mov    -0x118(%rbp),%eax
movzbl %al,%esi
lea    -0x110(%rbp),%rdx
xor    %edi,%edi
lea    -0x114(%rbp),%rcx
mov    $0x0,%al
call   1050 <Card_ReadBin_2G@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jge    1250 <MBBMS_TEL_GetSDVersion_2G+0x110>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1287 <MBBMS_TEL_GetSDVersion_2G+0x147>
lea    0xdf7(%rip),%rdi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%esi
mov    $0x0,%al
call   1030 <dump_mem@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1298 <MBBMS_TEL_GetSDVersion_2G+0x158>
movl   $0xffffffff,-0x124(%rbp)
ff ff ff
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MBBMS_TEL_GetSDVersion_2G>:
push   %rbp
push   %rbx
sub    $0x128,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,0x1b(%rsp)
movl   $0x19f003f,0x18(%rsp)
01
xor    %ebx,%ebx
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <Card_SelectFile_2G@plt>
test   %eax,%eax
js     11fe <MBBMS_TEL_GetSDVersion_2G+0xae>
cmpl   $0x4,0xc(%rsp)
jne    1213 <MBBMS_TEL_GetSDVersion_2G+0xc3>
movl   $0x100,0x10(%rsp)
xor    %ebx,%ebx
lea    0x20(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %edi,%edi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <Card_ReadBin_2G@plt>
test   %eax,%eax
js     1207 <MBBMS_TEL_GetSDVersion_2G+0xb7>
mov    %eax,%ebp
lea    0xe2b(%rip),%rdi
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   1040 <dump_mem@plt>
mov    %ebp,%ebx
jmp    1213 <MBBMS_TEL_GetSDVersion_2G+0xc3>
lea    0xe3d(%rip),%rdi
jmp    120e <MBBMS_TEL_GetSDVersion_2G+0xbe>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x128,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"MBBMS_TEL_GetSDVersion_2G\0A\00"
@__const.MBBMS_TEL_GetSDVersion_2G.cmd = [7 x i8] c"?\00\9F\01\00\00\00"
@.str.1 = [27 x i8] c"Card_SelectFile_2G fail \0A\00"
@.str.2 = [24 x i8] c"Card_ReadBin_2G fail \0A\00"
@.str.3 = [10 x i8] c"%s: res:\0A\00"
@__func__.MBBMS_TEL_GetSDVersion_2G = [26 x i8] c"MBBMS_TEL_GetSDVersion_2G\00"
define i32 @MBBMS_TEL_GetSDVersion_2G() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [7 x i8]
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = bitcast [7 x i8]* %8 to i8*
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%12 = call i32 (i8*, i32, i32*, i32*, ...) bitcast (i32 (...)* @Card_SelectFile_2G to i32 (i8*, i32, i32*, i32*, ...)*)(i8* %11, i32 4, i32* %4, i32* %5)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %37
17: ; preds = %0
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %21
20: ; preds = %17
br label %37
21: ; preds = %17
store i32 256, i32* %3
%22 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = zext i8 %23 to i32
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%26 = call i32 (i32, i32, i8*, i32*, ...) bitcast (i32 (...)* @Card_ReadBin_2G to i32 (i32, i32, i8*, i32*, ...)*)(i32 0, i32 %24, i8* %25, i32* %3)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %37
31: ; preds = %21
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @__func__.MBBMS_TEL_GetSDVersion_2G, i64 0, i64 0))
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%34 = load i32, i32* %3
%35 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @dump_mem to i32 (i8*, i32, ...)*)(i8* %33, i32 %34)
%36 = load i32, i32* %7
store i32 %36, i32* %1
br label %38
37: ; preds = %29, %20, %15
store i32 -1, i32* %7
store i32 0, i32* %1
br label %38
38: ; preds = %37, %31
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@__const.MBBMS_TEL_GetSDVersion_2G.cmd = [7 x i8] c"?\00\9F\01\00\00\00"
@.str.3 = [10 x i8] c"%s: res:\0A\00"
@str = [26 x i8] c"MBBMS_TEL_GetSDVersion_2G\00"
@str.4 = [23 x i8] c"Card_ReadBin_2G fail \00"
@str.5 = [26 x i8] c"Card_SelectFile_2G fail \00"
define i32 @MBBMS_TEL_GetSDVersion_2G() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [7 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, i32, i32*, i32*, ...) bitcast (i32 (...)* @Card_SelectFile_2G to i32 (i8*, i32, i32*, i32*, ...)*)(i8* %11, i32 4, i32* %3, i32* %4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
br label %28
16: ; preds = %0
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 4
br i1 %18, label %19, label %28
19: ; preds = %16
store i32 256, i32* %2
%20 = call i32 (i32, i32, i8*, i32*, ...) bitcast (i32 (...)* @Card_ReadBin_2G to i32 (i32, i32, i8*, i32*, ...)*)(i32 0, i32 4, i8* %6, i32* %2)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %28
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%26 = load i32, i32* %2
%27 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @dump_mem to i32 (i8*, i32, ...)*)(i8* %6, i32 %26)
br label %28
28: ; preds = %14, %22, %16, %24
%29 = phi i32 [ %20, %24 ], [ 0, %16 ], [ 0, %22 ], [ 0, %14 ]
ret i32 %29
}