#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 iEmvTermEnvironment();
int iHxGetData(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *, int *,
               unsigned char *);
unsigned char *pszEmvMsgTableGetInfo(int, unsigned char *);
int /*<<< orphan*/ strcpy(unsigned char *, unsigned char *);
char *pszHxGetMsg2(int iMsgType, int iMsgFor, unsigned char *pszMsg,
                   unsigned char *pszLanguage) {
  unsigned char szLanguageCode[3];
  int iTermEnv;
  int iLen;
  int iRet;
  iLen = 3;
  switch (iMsgFor) {
  case 3:
    iTermEnv = iEmvTermEnvironment();
    if (iTermEnv == 1)
      iRet = iHxGetData("\xDF\x90", NULL, NULL, &iLen, szLanguageCode);
    else
      iRet = iHxGetData("\xDF\x9A", NULL, NULL, &iLen, szLanguageCode);
    break;
  case 2:
    iRet = iHxGetData("\xDF\x9A", NULL, NULL, &iLen, szLanguageCode);
    break;
  case 1:
  case 0:
  default:
    iRet = iHxGetData("\xDF\x90", NULL, NULL, &iLen, szLanguageCode);
    break;
  }
  if (iRet != 0 || iLen != 2) {
    strcpy(pszMsg, pszEmvMsgTableGetInfo(iMsgType, NULL));
    if (pszLanguage)
      pszLanguage[0] = 0;
  } else {
    strcpy(pszMsg, pszEmvMsgTableGetInfo(iMsgType, szLanguageCode));
    if (pszLanguage)
      strcpy(pszLanguage, szLanguageCode);
  }
  return (pszMsg);
}


x86 assembly (clang, -O0):
<pszHxGetMsg2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x3,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2,%eax
jb     1210 <pszHxGetMsg2+0xd0>
jmp    1171 <pszHxGetMsg2+0x31>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     11ed <pszHxGetMsg2+0xad>
jmp    1182 <pszHxGetMsg2+0x42>
mov    -0x2c(%rbp),%eax
sub    $0x3,%eax
jne    1215 <pszHxGetMsg2+0xd5>
jmp    1193 <pszHxGetMsg2+0x53>
mov    $0x0,%al
call   1060 <iEmvTermEnvironment@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    11ca <pszHxGetMsg2+0x8a>
lea    -0x1b(%rbp),%r8
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x24(%rbp),%rcx
mov    %rdx,%rsi
call   1050 <iHxGetData@plt>
mov    %eax,-0x28(%rbp)
jmp    11e8 <pszHxGetMsg2+0xa8>
lea    -0x1b(%rbp),%r8
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x24(%rbp),%rcx
mov    %rdx,%rsi
call   1050 <iHxGetData@plt>
mov    %eax,-0x28(%rbp)
jmp    1233 <pszHxGetMsg2+0xf3>
lea    -0x1b(%rbp),%r8
lea    0xe0b(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x24(%rbp),%rcx
mov    %rdx,%rsi
call   1050 <iHxGetData@plt>
mov    %eax,-0x28(%rbp)
jmp    1233 <pszHxGetMsg2+0xf3>
jmp    1215 <pszHxGetMsg2+0xd5>
lea    -0x1b(%rbp),%r8
lea    0xde0(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x24(%rbp),%rcx
mov    %rdx,%rsi
call   1050 <iHxGetData@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1247 <pszHxGetMsg2+0x107>
cmpl   $0x2,-0x24(%rbp)
je     127e <pszHxGetMsg2+0x13e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pszEmvMsgTableGetInfo@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     1279 <pszHxGetMsg2+0x139>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    12bb <pszHxGetMsg2+0x17b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1b(%rbp),%rsi
call   1040 <pszEmvMsgTableGetInfo@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     12b6 <pszHxGetMsg2+0x176>
mov    -0x18(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12bb <pszHxGetMsg2+0x17b>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pszHxGetMsg2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%ebp
movl   $0x3,0xc(%rsp)
cmp    $0x2,%esi
je     1180 <pszHxGetMsg2+0x40>
cmp    $0x3,%esi
jne    1189 <pszHxGetMsg2+0x49>
xor    %eax,%eax
call   1060 <iEmvTermEnvironment@plt>
cmp    $0x1,%eax
lea    0xe8d(%rip),%rax
lea    0xe89(%rip),%rdi
cmove  %rax,%rdi
jmp    1190 <pszHxGetMsg2+0x50>
lea    0xe7c(%rip),%rdi
jmp    1190 <pszHxGetMsg2+0x50>
lea    0xe70(%rip),%rdi
lea    0xc(%rsp),%rcx
lea    0x9(%rsp),%r8
xor    %esi,%esi
xor    %edx,%edx
call   1050 <iHxGetData@plt>
test   %eax,%eax
jne    11d9 <pszHxGetMsg2+0x99>
cmpl   $0x2,0xc(%rsp)
jne    11d9 <pszHxGetMsg2+0x99>
lea    0x9(%rsp),%rsi
mov    %ebp,%edi
call   1040 <pszEmvMsgTableGetInfo@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
test   %r14,%r14
je     11f6 <pszHxGetMsg2+0xb6>
lea    0x9(%rsp),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
jmp    11f6 <pszHxGetMsg2+0xb6>
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <pszEmvMsgTableGetInfo@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
test   %r14,%r14
je     11f6 <pszHxGetMsg2+0xb6>
movb   $0x0,(%r14)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\DF\90\00"
@.str.1 = [3 x i8] c"\DF\9A\00"
define i8* @pszHxGetMsg2(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 3, i32* %11
%13 = load i32, i32* %6
switch i32 %13, label %29 [
i32 3, label %14
i32 2, label %25
i32 1, label %28
i32 0, label %28
]
14: ; preds = %4
%15 = call i32 (...) @iEmvTermEnvironment()
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%20 = call i32 @iHxGetData(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, i32* %11, i8* %19)
store i32 %20, i32* %12
br label %24
21: ; preds = %14
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%23 = call i32 @iHxGetData(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null, i32* null, i32* %11, i8* %22)
store i32 %23, i32* %12
br label %24
24: ; preds = %21, %18
br label %32
25: ; preds = %4
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%27 = call i32 @iHxGetData(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null, i32* null, i32* %11, i8* %26)
store i32 %27, i32* %12
br label %32
28: ; preds = %4, %4
br label %29
29: ; preds = %4, %28
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%31 = call i32 @iHxGetData(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, i32* %11, i8* %30)
store i32 %31, i32* %12
br label %32
32: ; preds = %29, %25, %24
%33 = load i32, i32* %12
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* %11
%37 = icmp ne i32 %36, 2
br i1 %37, label %38, label %49
38: ; preds = %35, %32
%39 = load i8*, i8** %7
%40 = load i32, i32* %5
%41 = call i8* @pszEmvMsgTableGetInfo(i32 %40, i8* null)
%42 = call i32 @strcpy(i8* %39, i8* %41)
%43 = load i8*, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
br label %48
48: ; preds = %45, %38
br label %62
49: ; preds = %35
%50 = load i8*, i8** %7
%51 = load i32, i32* %5
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%53 = call i8* @pszEmvMsgTableGetInfo(i32 %51, i8* %52)
%54 = call i32 @strcpy(i8* %50, i8* %53)
%55 = load i8*, i8** %8
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %61
57: ; preds = %49
%58 = load i8*, i8** %8
%59 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%60 = call i32 @strcpy(i8* %58, i8* %59)
br label %61
61: ; preds = %57, %49
br label %62
62: ; preds = %61, %48
%63 = load i8*, i8** %7
ret i8* %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"\DF\90\00"
@.str.1 = [3 x i8] c"\DF\9A\00"
define i8* @pszHxGetMsg2(i32 %0, i32 %1, i8* returned %2, i8* %3) {
%5 = alloca [3 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%8 = bitcast i32* %6 to i8*
store i32 3, i32* %6
switch i32 %1, label %13 [
i32 3, label %9
i32 2, label %14
]
9: ; preds = %4
%10 = tail call i32 (...) @iEmvTermEnvironment()
%11 = icmp eq i32 %10, 1
%12 = select i1 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
br label %14
13: ; preds = %4
br label %14
14: ; preds = %4, %9, %13
%15 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %13 ], [ %12, %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %4 ]
%16 = call i32 @iHxGetData(i8* %15, i32* null, i32* null, i32* %6, i8* %7)
%17 = icmp ne i32 %16, 0
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 2
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = call i8* @pszEmvMsgTableGetInfo(i32 %0, i8* null)
%23 = call i32 @strcpy(i8* %2, i8* %22)
%24 = icmp eq i8* %3, null
br i1 %24, label %32, label %25
25: ; preds = %21
store i8 0, i8* %3
br label %32
26: ; preds = %14
%27 = call i8* @pszEmvMsgTableGetInfo(i32 %0, i8* %7)
%28 = call i32 @strcpy(i8* %2, i8* %27)
%29 = icmp eq i8* %3, null
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @strcpy(i8* %3, i8* %7)
br label %32
32: ; preds = %26, %30, %21, %25
ret i8* %2
}