#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 _iSelProcessTlvObj61(unsigned char *, unsigned char);
int iTlvSearchObj(unsigned char *, int, unsigned int, unsigned char *,
                  unsigned char **);
int /*<<< orphan*/ strcpy(unsigned char *, char *);
unsigned int uiEmvCmdRdRec(unsigned char, unsigned char, unsigned char *,
                           unsigned char *);
int /*<<< orphan*/ vPushApduPrepare(int, unsigned char, int, int);
int _iSelProcessDirEF(unsigned char ucSFI) {
  unsigned char sRec[254];
  unsigned char ucRecNo;
  unsigned char ucRecLen;
  unsigned int uiIndex;
  unsigned char *psTlvObj61, ucTlvObj61Len;
  unsigned char *p;
  unsigned char sTagRoute[10];
  unsigned int uiRet;
  int iRet;
  vPushApduPrepare(1, ucSFI, 1, 255);
  for (ucRecNo = 1;; ucRecNo++) {
    uiRet = uiEmvCmdRdRec(ucSFI, ucRecNo, &ucRecLen, sRec);
    if (uiRet == 1)
      return (-11001);
    if (uiRet == 0x6a83) {
      if (ucRecNo == 1)
        return (-11010);
      return (0);
    }
    if (uiRet)
      return (-11002);
    strcpy(sTagRoute, "\x70");
    iRet = iTlvSearchObj(sRec, (int)ucRecLen, 0, sTagRoute, &p);
    if (iRet == -10002)
      return (-11012);
    if (iRet == -10004)
      return (-11012);
    for (uiIndex = 0;; uiIndex++) {
      strcpy(sTagRoute, "\x70"
                        "\x61");
      iRet =
          iTlvSearchObj(sRec, (int)ucRecLen, uiIndex, sTagRoute, &psTlvObj61);
      if (iRet == -10002)
        return (-11012);
      if (iRet == -10004)
        break;
      ucTlvObj61Len = (unsigned char)iRet;
      iRet = _iSelProcessTlvObj61(psTlvObj61, ucTlvObj61Len);
      if (iRet < 0)
        return (iRet);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<_iSelProcessDirEF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    $0x1,%edx
mov    $0xff,%ecx
mov    %edx,%edi
movzbl -0x5(%rbp),%esi
call   1040 <vPushApduPrepare@plt>
movb   $0x1,-0x111(%rbp)
mov    -0x5(%rbp),%sil
mov    -0x111(%rbp),%al
lea    -0x110(%rbp),%rcx
lea    -0x112(%rbp),%rdx
movzbl %sil,%edi
movzbl %al,%esi
call   1030 <uiEmvCmdRdRec@plt>
mov    %eax,-0x140(%rbp)
cmpl   $0x1,-0x140(%rbp)
jne    11c0 <_iSelProcessDirEF+0x70>
movl   $0xffffd507,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
cmpl   $0x6a83,-0x140(%rbp)
jne    11f8 <_iSelProcessDirEF+0xa8>
movzbl -0x111(%rbp),%eax
cmp    $0x1,%eax
jne    11ec <_iSelProcessDirEF+0x9c>
movl   $0xffffd4fe,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
movl   $0x0,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
cmpl   $0x0,-0x140(%rbp)
je     1211 <_iSelProcessDirEF+0xc1>
movl   $0xffffd506,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
lea    -0x13a(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x110(%rbp),%rdi
movzbl -0x112(%rbp),%esi
lea    -0x13a(%rbp),%rcx
xor    %edx,%edx
lea    -0x130(%rbp),%r8
call   1060 <iTlvSearchObj@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0xffffd8ee,-0x144(%rbp)
d8 ff ff
jne    1269 <_iSelProcessDirEF+0x119>
movl   $0xffffd4fc,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
cmpl   $0xffffd8ec,-0x144(%rbp)
d8 ff ff
jne    1285 <_iSelProcessDirEF+0x135>
movl   $0xffffd4fc,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
movl   $0x0,-0x118(%rbp)
lea    -0x13a(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x110(%rbp),%rdi
movzbl -0x112(%rbp),%esi
mov    -0x118(%rbp),%edx
lea    -0x13a(%rbp),%rcx
lea    -0x120(%rbp),%r8
call   1060 <iTlvSearchObj@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0xffffd8ee,-0x144(%rbp)
d8 ff ff
jne    12eb <_iSelProcessDirEF+0x19b>
movl   $0xffffd4fc,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
cmpl   $0xffffd8ec,-0x144(%rbp)
d8 ff ff
jne    1300 <_iSelProcessDirEF+0x1b0>
jmp    1359 <_iSelProcessDirEF+0x209>
mov    -0x144(%rbp),%eax
mov    %al,-0x121(%rbp)
mov    -0x120(%rbp),%rdi
movzbl -0x121(%rbp),%esi
call   1070 <_iSelProcessTlvObj61@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jge    1340 <_iSelProcessDirEF+0x1f0>
mov    -0x144(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1371 <_iSelProcessDirEF+0x221>
jmp    1345 <_iSelProcessDirEF+0x1f5>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    128f <_iSelProcessDirEF+0x13f>
jmp    135e <_iSelProcessDirEF+0x20e>
mov    -0x111(%rbp),%al
add    $0x1,%al
mov    %al,-0x111(%rbp)
jmp    117d <_iSelProcessDirEF+0x2d>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_iSelProcessDirEF>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %edi,%ebx
mov    $0x1,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0xff,%ecx
call   1040 <vPushApduPrepare@plt>
mov    $0x1,%r12b
movzbl %bl,%ebx
lea    0xa(%rsp),%rdx
lea    0x30(%rsp),%r14
lea    0x26(%rsp),%rbp
lea    0xe6d(%rip),%r15
lea    0x10(%rsp),%r13
mov    %ebx,0xc(%rsp)
movzbl %r12b,%esi
mov    %ebx,%edi
mov    %r14,%rcx
call   1030 <uiEmvCmdRdRec@plt>
test   %eax,%eax
jne    127d <_iSelProcessDirEF+0x12d>
mov    %rbp,%rdi
lea    0xe42(%rip),%rsi
call   1050 <strcpy@plt>
movzbl 0xa(%rsp),%esi
mov    %r14,%rdi
xor    %edx,%edx
mov    %rbp,%rcx
lea    0x18(%rsp),%r8
call   1060 <iTlvSearchObj@plt>
mov    $0xffffd4fc,%ebx
or     $0x2,%eax
cmp    $0xffffd8ee,%eax
je     1269 <_iSelProcessDirEF+0x119>
mov    %r12b,0xb(%rsp)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
movzbl 0xa(%rsp),%esi
mov    %r14,%rdi
mov    %r12d,%edx
mov    %rbp,%rcx
mov    %r13,%r8
call   1060 <iTlvSearchObj@plt>
cmp    $0xffffd8ec,%eax
je     1250 <_iSelProcessDirEF+0x100>
cmp    $0xffffd8ee,%eax
je     1269 <_iSelProcessDirEF+0x119>
mov    0x10(%rsp),%rdi
movzbl %al,%esi
call   1070 <_iSelProcessTlvObj61@plt>
add    $0x1,%r12d
test   %eax,%eax
jns    1200 <_iSelProcessDirEF+0xb0>
jmp    1267 <_iSelProcessDirEF+0x117>
cs nopw 0x0(%rax,%rax,1)
mov    0xb(%rsp),%r12b
add    $0x1,%r12b
mov    0xc(%rsp),%ebx
lea    0xa(%rsp),%rdx
jmp    119e <_iSelProcessDirEF+0x4e>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x1,%eax
je     1299 <_iSelProcessDirEF+0x149>
cmp    $0x6a83,%eax
jne    12a0 <_iSelProcessDirEF+0x150>
xor    %eax,%eax
cmp    $0x1,%r12b
mov    $0xffffd4fe,%ebx
cmovne %eax,%ebx
jmp    1269 <_iSelProcessDirEF+0x119>
mov    $0xffffd507,%ebx
jmp    1269 <_iSelProcessDirEF+0x119>
mov    $0xffffd506,%ebx
jmp    1269 <_iSelProcessDirEF+0x119>

LLVM IR (-O0):
@.str = [2 x i8] c"p\00"
@.str.1 = [3 x i8] c"pa\00"
define i32 @_iSelProcessDirEF(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca [254 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8*
%11 = alloca [10 x i8]
%12 = alloca i32
%13 = alloca i32
store i8 %0, i8* %3
%14 = load i8, i8* %3
%15 = call i32 @vPushApduPrepare(i32 1, i8 zeroext %14, i32 1, i32 255)
store i8 1, i8* %5
br label %16
16: ; preds = %84, %1
%17 = load i8, i8* %3
%18 = load i8, i8* %5
%19 = getelementptr inbounds [254 x i8], [254 x i8]* %4, i64 0, i64 0
%20 = call i32 @uiEmvCmdRdRec(i8 zeroext %17, i8 zeroext %18, i8* %6, i8* %19)
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 -11001, i32* %2
br label %87
24: ; preds = %16
%25 = load i32, i32* %12
%26 = icmp eq i32 %25, 27267
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -11010, i32* %2
br label %87
32: ; preds = %27
store i32 0, i32* %2
br label %87
33: ; preds = %24
%34 = load i32, i32* %12
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 -11002, i32* %2
br label %87
37: ; preds = %33
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%40 = getelementptr inbounds [254 x i8], [254 x i8]* %4, i64 0, i64 0
%41 = load i8, i8* %6
%42 = zext i8 %41 to i32
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%44 = call i32 @iTlvSearchObj(i8* %40, i32 %42, i32 0, i8* %43, i8** %10)
store i32 %44, i32* %13
%45 = load i32, i32* %13
%46 = icmp eq i32 %45, -10002
br i1 %46, label %47, label %48
47: ; preds = %37
store i32 -11012, i32* %2
br label %87
48: ; preds = %37
%49 = load i32, i32* %13
%50 = icmp eq i32 %49, -10004
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 -11012, i32* %2
br label %87
52: ; preds = %48
store i32 0, i32* %7
br label %53
53: ; preds = %80, %52
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%55 = call i32 @strcpy(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%56 = getelementptr inbounds [254 x i8], [254 x i8]* %4, i64 0, i64 0
%57 = load i8, i8* %6
%58 = zext i8 %57 to i32
%59 = load i32, i32* %7
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%61 = call i32 @iTlvSearchObj(i8* %56, i32 %58, i32 %59, i8* %60, i8** %8)
store i32 %61, i32* %13
%62 = load i32, i32* %13
%63 = icmp eq i32 %62, -10002
br i1 %63, label %64, label %65
64: ; preds = %53
store i32 -11012, i32* %2
br label %87
65: ; preds = %53
%66 = load i32, i32* %13
%67 = icmp eq i32 %66, -10004
br i1 %67, label %68, label %69
68: ; preds = %65
br label %83
69: ; preds = %65
%70 = load i32, i32* %13
%71 = trunc i32 %70 to i8
store i8 %71, i8* %9
%72 = load i8*, i8** %8
%73 = load i8, i8* %9
%74 = call i32 @_iSelProcessTlvObj61(i8* %72, i8 zeroext %73)
store i32 %74, i32* %13
%75 = load i32, i32* %13
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %69
%78 = load i32, i32* %13
store i32 %78, i32* %2
br label %87
79: ; preds = %69
br label %80
80: ; preds = %79
%81 = load i32, i32* %7
%82 = add i32 %81, 1
store i32 %82, i32* %7
br label %53
83: ; preds = %68
br label %84
84: ; preds = %83
%85 = load i8, i8* %5
%86 = add i8 %85, 1
store i8 %86, i8* %5
br label %16
87: ; preds = %77, %64, %51, %47, %36, %32, %31, %23
%88 = load i32, i32* %2
ret i32 %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"p\00"
@.str.1 = [3 x i8] c"pa\00"
define i32 @_iSelProcessDirEF(i8 zeroext %0) {
%2 = alloca [254 x i8]
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [10 x i8]
%7 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%11 = tail call i32 @vPushApduPrepare(i32 1, i8 zeroext %0, i32 1, i32 255)
br label %12
12: ; preds = %35, %1
%13 = phi i8 [ 1, %1 ], [ %36, %35 ]
%14 = call i32 @uiEmvCmdRdRec(i8 zeroext %0, i8 zeroext %13, i8* %3, i8* %7)
switch i32 %14, label %39 [
i32 1, label %37
i32 27267, label %15
i32 0, label %18
]
15: ; preds = %12
%16 = icmp eq i8 %13, 1
%17 = select i1 %16, i32 -11010, i32 0
br label %39
18: ; preds = %12
%19 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = call i32 @iTlvSearchObj(i8* %7, i32 %21, i32 0, i8* %10, i8** %5)
switch i32 %22, label %23 [
i32 -10002, label %37
i32 -10004, label %37
]
23: ; preds = %18, %29
%24 = phi i32 [ %34, %29 ], [ 0, %18 ]
%25 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8, i8* %3
%27 = zext i8 %26 to i32
%28 = call i32 @iTlvSearchObj(i8* %7, i32 %27, i32 %24, i8* %10, i8** %4)
switch i32 %28, label %29 [
i32 -10002, label %39
i32 -10004, label %35
]
29: ; preds = %23
%30 = trunc i32 %28 to i8
%31 = load i8*, i8** %4
%32 = call i32 @_iSelProcessTlvObj61(i8* %31, i8 zeroext %30)
%33 = icmp slt i32 %32, 0
%34 = add i32 %24, 1
br i1 %33, label %39, label %23
35: ; preds = %23
%36 = add i8 %13, 1
br label %12
37: ; preds = %12, %18, %18
%38 = phi i32 [ -11012, %18 ], [ -11012, %18 ], [ -11001, %12 ]
br label %39
39: ; preds = %29, %23, %12, %37, %15
%40 = phi i32 [ %17, %15 ], [ %38, %37 ], [ -11002, %12 ], [ %32, %29 ], [ -11012, %23 ]
ret i32 %40
}