#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*/ types;

/* Variables and functions */
int getword(char *, int);
scalar_t__ is_c_type(char *, char **, int, int);
int readvar(char *var, int maxlen) {
  char *types[] = {"short", "int", "float", "double", "void"};
  char word[maxlen];
  int type_len = sizeof(types) / sizeof(char *);
  while (getword(word, maxlen) > 0) {
    if (is_c_type(word, types, type_len, maxlen)) {
      return getword(var, maxlen);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<readvar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x30(%rbp)
movaps %xmm0,-0x40(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xea2(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
movl   $0x5,-0x54(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <getword@plt>
cmp    $0x0,%eax
jle    11f8 <readvar+0xd8>
mov    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <is_c_type@plt>
cmp    $0x0,%rax
je     11f3 <readvar+0xd3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <getword@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    1206 <readvar+0xe6>
jmp    11a6 <readvar+0x86>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readvar>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rsp,%r13
lea    0xebf(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    %esi,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x50(%rbp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <getword@plt>
test   %eax,%eax
jle    11c4 <readvar+0xa4>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5,%edx
mov    %r15d,%ecx
call   1030 <is_c_type@plt>
test   %rax,%rax
je     1190 <readvar+0x70>
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <getword@plt>
jmp    11c6 <readvar+0xa6>
xor    %eax,%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"short\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [6 x i8] c"float\00"
@.str.3 = [7 x i8] c"double\00"
@.str.4 = [5 x i8] c"void\00"
define i32 @readvar(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [5 x i8*]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = bitcast [5 x i8*]* %6 to i8*
%12 = bitcast i8* %11 to [5 x i8*]*
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %12, i32 0, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %12, i32 0, i32 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %12, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %12, i32 0, i32 3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %12, i32 0, i32 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8** %17
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i8, i64 %19
store i64 %19, i64* %8
store i32 5, i32* %9
br label %22
22: ; preds = %36, %2
%23 = load i32, i32* %5
%24 = call i32 @getword(i8* %21, i32 %23)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%28 = load i32, i32* %9
%29 = load i32, i32* %5
%30 = call i64 @is_c_type(i8* %21, i8** %27, i32 %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = call i32 @getword(i8* %33, i32 %34)
store i32 %35, i32* %3
store i32 1, i32* %10
br label %38
36: ; preds = %26
br label %22
37: ; preds = %22
store i32 0, i32* %3
store i32 1, i32* %10
br label %38
38: ; preds = %37, %32
%39 = load i8*, i8** %7
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [6 x i8] c"short\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [6 x i8] c"float\00"
@.str.3 = [7 x i8] c"double\00"
@.str.4 = [5 x i8] c"void\00"
define i32 @readvar(i8* %0, i32 %1) {
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = zext i32 %1 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
br label %13
13: ; preds = %16, %2
%14 = call i32 @getword(i8* %12, i32 %1)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i64 @is_c_type(i8* %12, i8** %5, i32 5, i32 %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %13, label %19
19: ; preds = %16
%20 = call i32 @getword(i8* %0, i32 %1)
br label %21
21: ; preds = %13, %19
%22 = phi i32 [ %20, %19 ], [ 0, %13 ]
ret i32 %22
}