#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 */
struct type {
  int dummy;
};
struct triple {
  int dummy;
};
struct compile_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ eat(struct compile_state *, int);
scalar_t__ istype(int);
struct triple *mk_cast_expr(struct compile_state *, struct type *,
                            struct triple *);
int peek(struct compile_state *);
int peek2(struct compile_state *);
struct type *type_name(struct compile_state *);
struct triple *unary_expr(struct compile_state *);
struct triple *cast_expr(struct compile_state *state) {
  struct triple *def;
  int tok1, tok2;
  tok1 = peek(state);
  tok2 = peek2(state);
  if ((tok1 == 10) && istype(tok2)) {
    struct type *type;
    eat(state, 10);
    type = type_name(state);
    eat(state, 11);
    def = mk_cast_expr(state, type, cast_expr(state));
  } else {
    def = unary_expr(state);
  }
  return def;
}


x86 assembly (clang, -O0):
<cast_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <peek@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <peek2@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    121b <cast_expr+0x9b>
mov    -0x18(%rbp),%edi
call   10a0 <istype@plt>
cmp    $0x0,%rax
je     121b <cast_expr+0x9b>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <eat@plt>
mov    -0x8(%rbp),%rdi
call   1070 <type_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xb,%esi
call   1040 <eat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <cast_expr@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1060 <mk_cast_expr@plt>
mov    %rax,-0x10(%rbp)
jmp    1228 <cast_expr+0xa8>
mov    -0x8(%rbp),%rdi
call   1090 <unary_expr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cast_expr>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <peek@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <peek2@plt>
cmp    $0xa,%ebp
jne    11e7 <cast_expr+0x67>
mov    %eax,%edi
call   10a0 <istype@plt>
test   %rax,%rax
je     11e7 <cast_expr+0x67>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <eat@plt>
mov    %rbx,%rdi
call   1070 <type_name@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0xb,%esi
call   1040 <eat@plt>
mov    %rbx,%rdi
call   1050 <cast_expr@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <mk_cast_expr@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1090 <unary_expr@plt>

LLVM IR (-O0):
%struct.triple = type { i32 }
%struct.compile_state = type { i32 }
%struct.type = type { i32 }
define %struct.triple* @cast_expr(%struct.compile_state* %0) {
%2 = alloca %struct.compile_state*
%3 = alloca %struct.triple*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.type*
store %struct.compile_state* %0, %struct.compile_state** %2
%7 = load %struct.compile_state*, %struct.compile_state** %2
%8 = call i32 @peek(%struct.compile_state* %7)
store i32 %8, i32* %4
%9 = load %struct.compile_state*, %struct.compile_state** %2
%10 = call i32 @peek2(%struct.compile_state* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %29
13: ; preds = %1
%14 = load i32, i32* %5
%15 = call i64 @istype(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load %struct.compile_state*, %struct.compile_state** %2
%19 = call i32 @eat(%struct.compile_state* %18, i32 10)
%20 = load %struct.compile_state*, %struct.compile_state** %2
%21 = call %struct.type* @type_name(%struct.compile_state* %20)
store %struct.type* %21, %struct.type** %6
%22 = load %struct.compile_state*, %struct.compile_state** %2
%23 = call i32 @eat(%struct.compile_state* %22, i32 11)
%24 = load %struct.compile_state*, %struct.compile_state** %2
%25 = load %struct.type*, %struct.type** %6
%26 = load %struct.compile_state*, %struct.compile_state** %2
%27 = call %struct.triple* @cast_expr(%struct.compile_state* %26)
%28 = call %struct.triple* @mk_cast_expr(%struct.compile_state* %24, %struct.type* %25, %struct.triple* %27)
store %struct.triple* %28, %struct.triple** %3
br label %32
29: ; preds = %13, %1
%30 = load %struct.compile_state*, %struct.compile_state** %2
%31 = call %struct.triple* @unary_expr(%struct.compile_state* %30)
store %struct.triple* %31, %struct.triple** %3
br label %32
32: ; preds = %29, %17
%33 = load %struct.triple*, %struct.triple** %3
ret %struct.triple* %33
}

LLVM IR (-O2):
%struct.triple = type { i32 }
%struct.compile_state = type { i32 }
%struct.type = type { i32 }
define %struct.triple* @cast_expr(%struct.compile_state* %0) {
%2 = tail call i32 @peek(%struct.compile_state* %0)
%3 = tail call i32 @peek2(%struct.compile_state* %0)
%4 = icmp eq i32 %2, 10
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = tail call i64 @istype(i32 %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %10
8: ; preds = %16, %10
%9 = phi %struct.triple* [ %15, %10 ], [ %17, %16 ]
ret %struct.triple* %9
10: ; preds = %5
%11 = tail call i32 @eat(%struct.compile_state* %0, i32 10)
%12 = tail call %struct.type* @type_name(%struct.compile_state* %0)
%13 = tail call i32 @eat(%struct.compile_state* %0, i32 11)
%14 = tail call %struct.triple* @cast_expr(%struct.compile_state* %0)
%15 = tail call %struct.triple* @mk_cast_expr(%struct.compile_state* %0, %struct.type* %12, %struct.triple* %14)
br label %8
16: ; preds = %5, %1
%17 = tail call %struct.triple* @unary_expr(%struct.compile_state* %0)
br label %8
}