#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 /*<<< orphan*/ noop(char *, char);
int get_calling_convention(char ch, const char **call_conv,
                           const char **exported, unsigned flags) {
  *call_conv = *exported = NULL;
  if (!(flags & ((0x0002) | (0x0010)))) {
    if (flags & (0x0001)) {
      if (((ch - 'A') % 2) == 1)
        *exported = "dll_export ";
      switch (ch) {
      case 'A':
      case 'B':
        *call_conv = "cdecl";
        break;
      case 'C':
      case 'D':
        *call_conv = "pascal";
        break;
      case 'E':
      case 'F':
        *call_conv = "thiscall";
        break;
      case 'G':
      case 'H':
        *call_conv = "stdcall";
        break;
      case 'I':
      case 'J':
        *call_conv = "fastcall";
        break;
      case 'K':
      case 'L':
        break;
      case 'M':
        *call_conv = "clrcall";
        break;
      default:
        noop("Unknown calling convention %c\n", ch);
        return (0);
      }
    } else {
      if (((ch - 'A') % 2) == 1)
        *exported = "__dll_export ";
      switch (ch) {
      case 'A':
      case 'B':
        *call_conv = "__cdecl";
        break;
      case 'C':
      case 'D':
        *call_conv = "__pascal";
        break;
      case 'E':
      case 'F':
        *call_conv = "__thiscall";
        break;
      case 'G':
      case 'H':
        *call_conv = "__stdcall";
        break;
      case 'I':
      case 'J':
        *call_conv = "__fastcall";
        break;
      case 'K':
      case 'L':
        break;
      case 'M':
        *call_conv = "__clrcall";
        break;
      default:
        noop("Unknown calling convention %c\n", ch);
        return (0);
      }
    }
  }
  return (1);
}


x86 assembly (clang, -O0):
<get_calling_convention>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x12,%eax
cmp    $0x0,%eax
jne    1332 <get_calling_convention+0x222>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1245 <get_calling_convention+0x135>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1183 <get_calling_convention+0x73>
mov    -0x18(%rbp),%rax
lea    0xf09(%rip),%rcx
mov    %rcx,(%rax)
movsbl -0x5(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0xc,%eax
ja     1224 <get_calling_convention+0x114>
mov    -0x28(%rbp),%rax
lea    0xe90(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
lea    0xedf(%rip),%rcx
mov    %rcx,(%rax)
jmp    1240 <get_calling_convention+0x130>
mov    -0x10(%rbp),%rax
lea    0xed4(%rip),%rcx
mov    %rcx,(%rax)
jmp    1240 <get_calling_convention+0x130>
mov    -0x10(%rbp),%rax
lea    0xeca(%rip),%rcx
mov    %rcx,(%rax)
jmp    1240 <get_calling_convention+0x130>
mov    -0x10(%rbp),%rax
lea    0xec2(%rip),%rcx
mov    %rcx,(%rax)
jmp    1240 <get_calling_convention+0x130>
mov    -0x10(%rbp),%rax
lea    0xeb9(%rip),%rcx
mov    %rcx,(%rax)
jmp    1240 <get_calling_convention+0x130>
jmp    1240 <get_calling_convention+0x130>
mov    -0x10(%rbp),%rax
lea    0xeac(%rip),%rcx
mov    %rcx,(%rax)
jmp    1240 <get_calling_convention+0x130>
lea    0xe3d(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1030 <noop@plt>
movl   $0x0,-0x4(%rbp)
jmp    1339 <get_calling_convention+0x229>
jmp    132d <get_calling_convention+0x21d>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    126b <get_calling_convention+0x15b>
mov    -0x18(%rbp),%rax
lea    0xe1f(%rip),%rcx
mov    %rcx,(%rax)
movsbl -0x5(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xc,%eax
ja     130c <get_calling_convention+0x1fc>
mov    -0x30(%rbp),%rax
lea    0xd74(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
lea    0xdf5(%rip),%rcx
mov    %rcx,(%rax)
jmp    1328 <get_calling_convention+0x218>
mov    -0x10(%rbp),%rax
lea    0xdea(%rip),%rcx
mov    %rcx,(%rax)
jmp    1328 <get_calling_convention+0x218>
mov    -0x10(%rbp),%rax
lea    0xde0(%rip),%rcx
mov    %rcx,(%rax)
jmp    1328 <get_calling_convention+0x218>
mov    -0x10(%rbp),%rax
lea    0xdd8(%rip),%rcx
mov    %rcx,(%rax)
jmp    1328 <get_calling_convention+0x218>
mov    -0x10(%rbp),%rax
lea    0xdcf(%rip),%rcx
mov    %rcx,(%rax)
jmp    1328 <get_calling_convention+0x218>
jmp    1328 <get_calling_convention+0x218>
mov    -0x10(%rbp),%rax
lea    0xdc2(%rip),%rcx
mov    %rcx,(%rax)
jmp    1328 <get_calling_convention+0x218>
lea    0xd55(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1030 <noop@plt>
movl   $0x0,-0x4(%rbp)
jmp    1339 <get_calling_convention+0x229>
jmp    132d <get_calling_convention+0x21d>
jmp    1332 <get_calling_convention+0x222>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_calling_convention>:
push   %rax
movq   $0x0,(%rdx)
movq   $0x0,(%rsi)
mov    $0x1,%eax
test   $0x12,%cl
je     112b <get_calling_convention+0x1b>
pop    %rcx
ret
movsbl %dil,%r8d
lea    -0x41(%r8),%r9d
movzwl %r9w,%r10d
mov    %r10d,%edi
shr    $0xf,%edi
add    %r10d,%edi
and    $0xfffffffe,%edi
sub    %edi,%r10d
test   $0x1,%cl
jne    117e <get_calling_convention+0x6e>
cmp    $0x1,%r10w
jne    115c <get_calling_convention+0x4c>
lea    0xf2e(%rip),%rcx
mov    %rcx,(%rdx)
cmp    $0xc,%r9d
ja     11db <get_calling_convention+0xcb>
lea    0xecb(%rip),%rcx
movslq (%rcx,%r9,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xf1c(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
cmp    $0x1,%r10w
jne    118f <get_calling_convention+0x7f>
lea    0xefd(%rip),%rcx
mov    %rcx,(%rdx)
cmp    $0xc,%r9d
ja     11db <get_calling_convention+0xcb>
lea    0xe64(%rip),%rcx
movslq (%rcx,%r9,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xeeb(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xefc(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xef5(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xed6(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xed6(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xee2(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xe86(%rip),%rdi
mov    %r8d,%esi
call   1030 <noop@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeaa(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xeaa(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xeb6(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xeb6(%rip),%rcx
jmp    1219 <get_calling_convention+0x109>
lea    0xeaf(%rip),%rcx
mov    %rcx,(%rsi)
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"dll_export \00"
@.str.1 = [6 x i8] c"cdecl\00"
@.str.2 = [7 x i8] c"pascal\00"
@.str.3 = [9 x i8] c"thiscall\00"
@.str.4 = [8 x i8] c"stdcall\00"
@.str.5 = [9 x i8] c"fastcall\00"
@.str.6 = [8 x i8] c"clrcall\00"
@.str.7 = [31 x i8] c"Unknown calling convention %c\0A\00"
@.str.8 = [14 x i8] c"__dll_export \00"
@.str.9 = [8 x i8] c"__cdecl\00"
@.str.10 = [9 x i8] c"__pascal\00"
@.str.11 = [11 x i8] c"__thiscall\00"
@.str.12 = [10 x i8] c"__stdcall\00"
@.str.13 = [11 x i8] c"__fastcall\00"
@.str.14 = [10 x i8] c"__clrcall\00"
define i32 @get_calling_convention(i8 signext %0, i8** %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
store i8 %0, i8* %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%10 = load i8**, i8*** %8
store i8* null, i8** %10
%11 = load i8**, i8*** %7
store i8* null, i8** %11
%12 = load i32, i32* %9
%13 = and i32 %12, 18
%14 = icmp ne i32 %13, 0
br i1 %14, label %76, label %15
15: ; preds = %4
%16 = load i32, i32* %9
%17 = and i32 %16, 1
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %47
19: ; preds = %15
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 65
%23 = srem i32 %22, 2
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i8**, i8*** %8
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %26
br label %27
27: ; preds = %25, %19
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
switch i32 %29, label %43 [
i32 65, label %30
i32 66, label %30
i32 67, label %32
i32 68, label %32
i32 69, label %34
i32 70, label %34
i32 71, label %36
i32 72, label %36
i32 73, label %38
i32 74, label %38
i32 75, label %40
i32 76, label %40
i32 77, label %41
]
30: ; preds = %27, %27
%31 = load i8**, i8*** %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %31
br label %46
32: ; preds = %27, %27
%33 = load i8**, i8*** %7
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %33
br label %46
34: ; preds = %27, %27
%35 = load i8**, i8*** %7
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %35
br label %46
36: ; preds = %27, %27
%37 = load i8**, i8*** %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %37
br label %46
38: ; preds = %27, %27
%39 = load i8**, i8*** %7
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8** %39
br label %46
40: ; preds = %27, %27
br label %46
41: ; preds = %27
%42 = load i8**, i8*** %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %42
br label %46
43: ; preds = %27
%44 = load i8, i8* %6
%45 = call i32 @noop(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8 signext %44)
store i32 0, i32* %5
br label %77
46: ; preds = %41, %40, %38, %36, %34, %32, %30
br label %75
47: ; preds = %15
%48 = load i8, i8* %6
%49 = sext i8 %48 to i32
%50 = sub nsw i32 %49, 65
%51 = srem i32 %50, 2
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = load i8**, i8*** %8
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %54
br label %55
55: ; preds = %53, %47
%56 = load i8, i8* %6
%57 = sext i8 %56 to i32
switch i32 %57, label %71 [
i32 65, label %58
i32 66, label %58
i32 67, label %60
i32 68, label %60
i32 69, label %62
i32 70, label %62
i32 71, label %64
i32 72, label %64
i32 73, label %66
i32 74, label %66
i32 75, label %68
i32 76, label %68
i32 77, label %69
]
58: ; preds = %55, %55
%59 = load i8**, i8*** %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8** %59
br label %74
60: ; preds = %55, %55
%61 = load i8**, i8*** %7
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8** %61
br label %74
62: ; preds = %55, %55
%63 = load i8**, i8*** %7
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8** %63
br label %74
64: ; preds = %55, %55
%65 = load i8**, i8*** %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i8** %65
br label %74
66: ; preds = %55, %55
%67 = load i8**, i8*** %7
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0), i8** %67
br label %74
68: ; preds = %55, %55
br label %74
69: ; preds = %55
%70 = load i8**, i8*** %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8** %70
br label %74
71: ; preds = %55
%72 = load i8, i8* %6
%73 = call i32 @noop(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8 signext %72)
store i32 0, i32* %5
br label %77
74: ; preds = %69, %68, %66, %64, %62, %60, %58
br label %75
75: ; preds = %74, %46
br label %76
76: ; preds = %75, %4
store i32 1, i32* %5
br label %77
77: ; preds = %76, %71, %43
%78 = load i32, i32* %5
ret i32 %78
}

LLVM IR (-O2):
@.str = [12 x i8] c"dll_export \00"
@.str.1 = [6 x i8] c"cdecl\00"
@.str.2 = [7 x i8] c"pascal\00"
@.str.3 = [9 x i8] c"thiscall\00"
@.str.4 = [8 x i8] c"stdcall\00"
@.str.5 = [9 x i8] c"fastcall\00"
@.str.6 = [8 x i8] c"clrcall\00"
@.str.7 = [31 x i8] c"Unknown calling convention %c\0A\00"
@.str.8 = [14 x i8] c"__dll_export \00"
@.str.9 = [8 x i8] c"__cdecl\00"
@.str.10 = [9 x i8] c"__pascal\00"
@.str.11 = [11 x i8] c"__thiscall\00"
@.str.12 = [10 x i8] c"__stdcall\00"
@.str.13 = [11 x i8] c"__fastcall\00"
@.str.14 = [10 x i8] c"__clrcall\00"
define i32 @get_calling_convention(i8 signext %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2, i32 %3) {
store i8* null, i8** %2
store i8* null, i8** %1
%5 = and i32 %3, 18
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %37
7: ; preds = %4
%8 = and i32 %3, 1
%9 = icmp eq i32 %8, 0
%10 = sext i8 %0 to i32
%11 = sext i8 %0 to i16
%12 = add nsw i16 %11, -65
%13 = srem i16 %12, 2
%14 = icmp eq i16 %13, 1
br i1 %9, label %26, label %15
15: ; preds = %7
br i1 %14, label %16, label %17
16: ; preds = %15
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %16, %15
switch i32 %10, label %24 [
i32 65, label %18
i32 66, label %18
i32 67, label %19
i32 68, label %19
i32 69, label %20
i32 70, label %20
i32 71, label %21
i32 72, label %21
i32 73, label %22
i32 74, label %22
i32 75, label %37
i32 76, label %37
i32 77, label %23
]
18: ; preds = %17, %17
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %37
19: ; preds = %17, %17
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %37
20: ; preds = %17, %17
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %37
21: ; preds = %17, %17
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %1
br label %37
22: ; preds = %17, %17
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %37
23: ; preds = %17
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %37
24: ; preds = %17
%25 = tail call i32 @noop(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8 signext %0)
br label %37
26: ; preds = %7
br i1 %14, label %27, label %28
27: ; preds = %26
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %27, %26
switch i32 %10, label %35 [
i32 65, label %29
i32 66, label %29
i32 67, label %30
i32 68, label %30
i32 69, label %31
i32 70, label %31
i32 71, label %32
i32 72, label %32
i32 73, label %33
i32 74, label %33
i32 75, label %37
i32 76, label %37
i32 77, label %34
]
29: ; preds = %28, %28
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8** %1
br label %37
30: ; preds = %28, %28
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8** %1
br label %37
31: ; preds = %28, %28
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8** %1
br label %37
32: ; preds = %28, %28
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0), i8** %1
br label %37
33: ; preds = %28, %28
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.13, i64 0, i64 0), i8** %1
br label %37
34: ; preds = %28
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8** %1
br label %37
35: ; preds = %28
%36 = tail call i32 @noop(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8 signext %0)
br label %37
37: ; preds = %4, %29, %30, %31, %32, %33, %34, %28, %28, %18, %19, %20, %21, %22, %23, %17, %17, %35, %24
%38 = phi i32 [ 0, %24 ], [ 0, %35 ], [ 1, %17 ], [ 1, %17 ], [ 1, %23 ], [ 1, %22 ], [ 1, %21 ], [ 1, %20 ], [ 1, %19 ], [ 1, %18 ], [ 1, %28 ], [ 1, %28 ], [ 1, %34 ], [ 1, %33 ], [ 1, %32 ], [ 1, %31 ], [ 1, %30 ], [ 1, %29 ], [ 1, %4 ]
ret i32 %38
}