#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 */
typedef int /*<<< orphan*/ sTlvObj;

/* Variables and functions */
int iHxEmvGetData(unsigned char *, int *, unsigned char *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ vLongToStr(unsigned long, int, unsigned char *);
int iGenOutData(unsigned char *psOutData) {
  static unsigned short auiTag[] = {0x9F26, 0x9F27, 0x9F10, 0x9F37, 0x9F36,
                                    0x9500, 0x9A00, 0x9C00, 0x9F02, 0x5F2A,
                                    0x8200, 0x9F1A, 0x9F03, 0x9F33, 0x9F13,
                                    0x5A00, 0x5F34, 0xDF31, 0};
  int i;
  int iOutLen;
  iOutLen = 0;
  for (i = 0;; i++) {
    unsigned char sTag[2], sTlvObj[270];
    int iTlvObjLen;
    int iRet;
    if (auiTag[i] == 0)
      break;
    vLongToStr((unsigned long)auiTag[i], 2, sTag);
    iTlvObjLen = sizeof(sTlvObj);
    iRet = iHxEmvGetData(sTag, &iTlvObjLen, sTlvObj, NULL, NULL);
    if (iRet)
      continue;
    memcpy(psOutData + iOutLen, sTlvObj, iTlvObjLen);
    iOutLen += iTlvObjLen;
  }
  return (iOutLen);
}


x86 assembly (clang, -O0):
<iGenOutData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
lea    0x2ee8(%rip),%rax
movzwl (%rax,%rcx,2),%eax
cmp    $0x0,%eax
jne    116a <iGenOutData+0x3a>
jmp    1201 <iGenOutData+0xd1>
movslq -0xc(%rbp),%rcx
lea    0x2ecb(%rip),%rax
movzwl (%rax,%rcx,2),%eax
mov    %eax,%edi
lea    -0x12(%rbp),%rdx
mov    $0x2,%esi
call   1050 <vLongToStr@plt>
movl   $0x10e,-0x124(%rbp)
lea    -0x12(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    -0x124(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1030 <iHxEmvGetData@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
je     11ca <iGenOutData+0x9a>
jmp    11f3 <iGenOutData+0xc3>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x124(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <iGenOutData+0x1d>
mov    -0x10(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iGenOutData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdi,0x8(%rsp)
xor    %ebp,%ebp
lea    0xeb1(%rip),%r14
lea    0x6(%rsp),%r13
mov    %rsp,%r15
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
jmp    116a <iGenOutData+0x3a>
add    $0x2,%rbp
cmp    $0x24,%rbp
je     11b7 <iGenOutData+0x87>
movzwl 0x0(%rbp,%r14,1),%edi
mov    $0x2,%esi
mov    %r13,%rdx
call   1050 <vLongToStr@plt>
movl   $0x10e,(%rsp)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <iHxEmvGetData@plt>
test   %eax,%eax
jne    1160 <iGenOutData+0x30>
movslq %ebx,%rbx
mov    0x8(%rsp),%rax
lea    (%rax,%rbx,1),%rdi
mov    (%rsp),%edx
mov    %r12,%rsi
call   1040 <memcpy@plt>
add    (%rsp),%ebx
jmp    1160 <iGenOutData+0x30>
mov    %ebx,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@iGenOutData.auiTag = internal global [19 x i16] [i16 -24794, i16 -24793, i16 -24816, i16 -24777, i16 -24778, i16 -27392, i16 -26112, i16 -25600, i16 -24830, i16 24362, i16 -32256, i16 -24806, i16 -24829, i16 -24781, i16 -24813, i16 23040, i16 24372, i16 -8399, i16 0]
define i32 @iGenOutData(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8]
%6 = alloca [270 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %9
9: ; preds = %42, %1
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [19 x i16], [19 x i16]* @iGenOutData.auiTag, i64 0, i64 %11
%13 = load i16, i16* %12
%14 = zext i16 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
br label %45
17: ; preds = %9
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [19 x i16], [19 x i16]* @iGenOutData.auiTag, i64 0, i64 %19
%21 = load i16, i16* %20
%22 = zext i16 %21 to i64
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%24 = call i32 @vLongToStr(i64 %22, i32 2, i8* %23)
store i32 270, i32* %7
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [270 x i8], [270 x i8]* %6, i64 0, i64 0
%27 = call i32 @iHxEmvGetData(i8* %25, i32* %7, i8* %26, i32* null, i32* null)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %17
br label %42
31: ; preds = %17
%32 = load i8*, i8** %2
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds [270 x i8], [270 x i8]* %6, i64 0, i64 0
%37 = load i32, i32* %7
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i32, i32* %7
%40 = load i32, i32* %4
%41 = add nsw i32 %40, %39
store i32 %41, i32* %4
br label %42
42: ; preds = %31, %30
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %9
45: ; preds = %16
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@iGenOutData.auiTag = internal unnamed_addr constant [19 x i16] [i16 -24794, i16 -24793, i16 -24816, i16 -24777, i16 -24778, i16 -27392, i16 -26112, i16 -25600, i16 -24830, i16 24362, i16 -32256, i16 -24806, i16 -24829, i16 -24781, i16 -24813, i16 23040, i16 24372, i16 -8399, i16 0]
define i32 @iGenOutData(i8* %0) {
%2 = alloca [2 x i8]
%3 = alloca [270 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [270 x i8], [270 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
br label %8
8: ; preds = %1, %24
%9 = phi i64 [ 0, %1 ], [ %26, %24 ]
%10 = phi i32 [ 0, %1 ], [ %25, %24 ]
%11 = getelementptr inbounds [19 x i16], [19 x i16]* @iGenOutData.auiTag, i64 0, i64 %9
%12 = load i16, i16* %11
%13 = zext i16 %12 to i64
%14 = call i32 @vLongToStr(i64 %13, i32 2, i8* %5)
store i32 270, i32* %4
%15 = call i32 @iHxEmvGetData(i8* %5, i32* %4, i8* %6, i32* null, i32* null)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %8
%18 = sext i32 %10 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i32, i32* %4
%21 = call i32 @memcpy(i8* %19, i8* %6, i32 %20)
%22 = load i32, i32* %4
%23 = add nsw i32 %22, %10
br label %24
24: ; preds = %17, %8
%25 = phi i32 [ %10, %8 ], [ %23, %17 ]
%26 = add nuw nsw i64 %9, 1
%27 = icmp eq i64 %26, 18
br i1 %27, label %28, label %8
28: ; preds = %24
ret i32 %25
}