#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 */
scalar_t__ amatch(char *, int);
int /*<<< orphan*/ error(char *);
int find_tag(char *);
int /*<<< orphan*/ illname();
scalar_t__ symname(char *);
int get_type(void) {
  int otag;
  char symbol_name[32];
  int sflag = 0;
  if (sflag = amatch("struct", 6) || amatch("union", 5)) {
    if (symname(symbol_name) == 0)
      illname();
    if ((otag = find_tag(symbol_name)) == -1)
      error("unknown struct/union");
    return 2;
  }
  if (amatch("void", 4)) {
    return (0 << 2);
  }
  if (amatch("unsigned", 8)) {
    if (amatch("char", 4)) {
      return ((1 << 2) + 1);
    } else if (amatch("int", 3)) {
      return ((2 << 2) + 1);
    }
  } else if (amatch("signed", 6)) {
    if (amatch("char", 4)) {
      return (1 << 2);
    } else if (amatch("int", 3)) {
      return (2 << 2);
    }
  } else if (amatch("char", 4)) {
    return (1 << 2);
  } else if (amatch("int", 3)) {
    return (2 << 2);
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x34(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x6,%esi
call   1050 <amatch@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x35(%rbp)
jne    119d <get_type+0x4d>
lea    0xe8d(%rip),%rdi
mov    $0x5,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x34(%rbp)
test   $0x1,%al
jne    11b8 <get_type+0x68>
jmp    11ff <get_type+0xaf>
lea    -0x30(%rbp),%rdi
call   1040 <symname@plt>
cmp    $0x0,%rax
jne    11d2 <get_type+0x82>
mov    $0x0,%al
call   1070 <illname@plt>
lea    -0x30(%rbp),%rdi
call   1030 <find_tag@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11f3 <get_type+0xa3>
lea    0xe19(%rip),%rdi
call   1060 <error@plt>
movl   $0x2,-0x4(%rbp)
jmp    1370 <get_type+0x220>
lea    0xe16(%rip),%rdi
mov    $0x4,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     1226 <get_type+0xd6>
movl   $0x0,-0x4(%rbp)
jmp    1370 <get_type+0x220>
lea    0xdf4(%rip),%rdi
mov    $0x8,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     1299 <get_type+0x149>
lea    0xde2(%rip),%rdi
mov    $0x4,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     1268 <get_type+0x118>
movl   $0x5,-0x4(%rbp)
jmp    1370 <get_type+0x220>
lea    0xdc0(%rip),%rdi
mov    $0x3,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     128f <get_type+0x13f>
movl   $0x9,-0x4(%rbp)
jmp    1370 <get_type+0x220>
jmp    1294 <get_type+0x144>
jmp    1369 <get_type+0x219>
lea    0xd83(%rip),%rdi
mov    $0x6,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     130c <get_type+0x1bc>
lea    0xd6f(%rip),%rdi
mov    $0x4,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     12db <get_type+0x18b>
movl   $0x4,-0x4(%rbp)
jmp    1370 <get_type+0x220>
lea    0xd4d(%rip),%rdi
mov    $0x3,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     1302 <get_type+0x1b2>
movl   $0x8,-0x4(%rbp)
jmp    1370 <get_type+0x220>
jmp    1307 <get_type+0x1b7>
jmp    1364 <get_type+0x214>
lea    0xd17(%rip),%rdi
mov    $0x4,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     1333 <get_type+0x1e3>
movl   $0x4,-0x4(%rbp)
jmp    1370 <get_type+0x220>
lea    0xcf5(%rip),%rdi
mov    $0x3,%esi
call   1050 <amatch@plt>
cmp    $0x0,%rax
je     135a <get_type+0x20a>
movl   $0x8,-0x4(%rbp)
jmp    1370 <get_type+0x220>
jmp    135f <get_type+0x20f>
jmp    1364 <get_type+0x214>
jmp    1369 <get_type+0x219>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_type>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xea2(%rip),%rdi
mov    $0x6,%esi
call   1050 <amatch@plt>
test   %rax,%rax
jne    1183 <get_type+0x33>
lea    0xea2(%rip),%rdi
mov    $0x5,%esi
call   1050 <amatch@plt>
test   %rax,%rax
je     11b7 <get_type+0x67>
mov    %rsp,%rdi
call   1040 <symname@plt>
test   %rax,%rax
jne    1197 <get_type+0x47>
xor    %eax,%eax
call   1070 <illname@plt>
mov    %rsp,%rdi
call   1030 <find_tag@plt>
mov    $0x2,%ebx
cmp    $0xffffffff,%eax
jne    11cf <get_type+0x7f>
lea    0xe57(%rip),%rdi
call   1060 <error@plt>
jmp    11cf <get_type+0x7f>
lea    0xe5e(%rip),%rdi
mov    $0x4,%esi
call   1050 <amatch@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d9 <get_type+0x89>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe41(%rip),%rdi
mov    $0x8,%esi
call   1050 <amatch@plt>
test   %rax,%rax
je     1222 <get_type+0xd2>
lea    0xe34(%rip),%rdi
mov    $0x4,%esi
call   1050 <amatch@plt>
mov    $0x5,%ebx
test   %rax,%rax
jne    11cf <get_type+0x7f>
lea    0xe1e(%rip),%rdi
mov    $0x3,%esi
call   1050 <amatch@plt>
mov    $0x9,%ebx
jmp    126e <get_type+0x11e>
lea    0xdfa(%rip),%rdi
mov    $0x6,%esi
call   1050 <amatch@plt>
mov    %rax,%r14
lea    0xded(%rip),%rdi
mov    $0x4,%ebx
mov    $0x4,%esi
call   1050 <amatch@plt>
test   %r14,%r14
test   %rax,%rax
jne    11cf <get_type+0x7f>
lea    0xdd0(%rip),%rdi
mov    $0x3,%esi
call   1050 <amatch@plt>
mov    $0x8,%ebx
test   %rax,%rax
jne    11cf <get_type+0x7f>
mov    $0xffffffff,%ebx
jmp    11cf <get_type+0x7f>

LLVM IR (-O0):
@.str = [7 x i8] c"struct\00"
@.str.1 = [6 x i8] c"union\00"
@.str.2 = [21 x i8] c"unknown struct/union\00"
@.str.3 = [5 x i8] c"void\00"
@.str.4 = [9 x i8] c"unsigned\00"
@.str.5 = [5 x i8] c"char\00"
@.str.6 = [4 x i8] c"int\00"
@.str.7 = [7 x i8] c"signed\00"
define i32 @get_type() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i32
store i32 0, i32* %4
%5 = call i64 @amatch(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%6 = icmp ne i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i64 @amatch(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%9 = icmp ne i64 %8, 0
br label %10
10: ; preds = %7, %0
%11 = phi i1 [ true, %0 ], [ %9, %7 ]
%12 = zext i1 %11 to i32
store i32 %12, i32* %4
br i1 %11, label %13, label %26
13: ; preds = %10
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%15 = call i64 @symname(i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (...) @illname()
br label %19
19: ; preds = %17, %13
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%21 = call i32 @find_tag(i8* %20)
store i32 %21, i32* %2
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
store i32 2, i32* %1
br label %68
26: ; preds = %10
%27 = call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 0, i32* %1
br label %68
30: ; preds = %26
%31 = call i64 @amatch(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 5, i32* %1
br label %68
37: ; preds = %33
%38 = call i64 @amatch(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 9, i32* %1
br label %68
41: ; preds = %37
br label %42
42: ; preds = %41
br label %67
43: ; preds = %30
%44 = call i64 @amatch(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %56
46: ; preds = %43
%47 = call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 4, i32* %1
br label %68
50: ; preds = %46
%51 = call i64 @amatch(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %50
store i32 8, i32* %1
br label %68
54: ; preds = %50
br label %55
55: ; preds = %54
br label %66
56: ; preds = %43
%57 = call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
store i32 4, i32* %1
br label %68
60: ; preds = %56
%61 = call i64 @amatch(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %60
store i32 8, i32* %1
br label %68
64: ; preds = %60
br label %65
65: ; preds = %64
br label %66
66: ; preds = %65, %55
br label %67
67: ; preds = %66, %42
store i32 -1, i32* %1
br label %68
68: ; preds = %67, %63, %59, %53, %49, %40, %36, %29, %25
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@.str = [7 x i8] c"struct\00"
@.str.1 = [6 x i8] c"union\00"
@.str.2 = [21 x i8] c"unknown struct/union\00"
@.str.3 = [5 x i8] c"void\00"
@.str.4 = [9 x i8] c"unsigned\00"
@.str.5 = [5 x i8] c"char\00"
@.str.6 = [4 x i8] c"int\00"
@.str.7 = [7 x i8] c"signed\00"
define i32 @get_type() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @amatch(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i64 @amatch(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %0, %5
%9 = call i64 @symname(i8* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (...) @illname()
br label %13
13: ; preds = %11, %8
%14 = call i32 @find_tag(i8* %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %44
16: ; preds = %13
%17 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %44
18: ; preds = %5
%19 = tail call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %18
%22 = tail call i64 @amatch(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = tail call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = tail call i64 @amatch(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %43, label %44
30: ; preds = %21
%31 = tail call i64 @amatch(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
%32 = icmp eq i64 %31, 0
%33 = tail call i64 @amatch(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%34 = icmp eq i64 %33, 0
br i1 %32, label %39, label %35
35: ; preds = %30
br i1 %34, label %36, label %44
36: ; preds = %35
%37 = tail call i64 @amatch(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %44
39: ; preds = %30
br i1 %34, label %40, label %44
40: ; preds = %39
%41 = tail call i64 @amatch(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %36, %40, %27
br label %44
44: ; preds = %40, %39, %36, %35, %27, %24, %18, %13, %16, %43
%45 = phi i32 [ -1, %43 ], [ 2, %16 ], [ 2, %13 ], [ 0, %18 ], [ 5, %24 ], [ 9, %27 ], [ 4, %35 ], [ 8, %36 ], [ 4, %39 ], [ 8, %40 ]
ret i32 %45
}