#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*/ arithmetic(struct compile_state *, struct triple *);
struct type *arithmetic_result(struct compile_state *, struct triple *,
                               struct triple *);
struct triple *cast_expr(struct compile_state *);
int /*<<< orphan*/ eat(struct compile_state *, int);
int is_signed(struct type *);
int peek(struct compile_state *);
struct triple *read_expr(struct compile_state *, struct triple *);
struct triple *triple(struct compile_state *, int, struct type *,
                      struct triple *, struct triple *);
struct triple *mult_expr(struct compile_state *state) {
  struct triple *def;
  int done;
  def = cast_expr(state);
  do {
    struct triple *left, *right;
    struct type *result_type;
    int tok, op, sign;
    done = 0;
    tok = peek(state);
    switch (tok) {
    case 12:
    case 40:
    case 41:
      left = read_expr(state, def);
      arithmetic(state, left);
      eat(state, tok);
      right = read_expr(state, cast_expr(state));
      arithmetic(state, right);
      result_type = arithmetic_result(state, left, right);
      sign = is_signed(result_type);
      op = -1;
      switch (tok) {
      case 12:
        op = sign ? 2 : 3;
        break;
      case 40:
        op = sign ? 4 : 5;
        break;
      case 41:
        op = sign ? 6 : 7;
        break;
      }
      def = triple(state, op, result_type, left, right);
      break;
    default:
      done = 1;
      break;
    }
  } while (!done);
  return def;
}


x86 assembly (clang, -O0):
<mult_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <cast_expr@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <peek@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0xc,%eax
je     11d4 <mult_expr+0x54>
jmp    11c0 <mult_expr+0x40>
mov    -0x40(%rbp),%eax
add    $0xffffffd8,%eax
sub    $0x1,%eax
ja     12f3 <mult_expr+0x173>
jmp    11d4 <mult_expr+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <read_expr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <arithmetic@plt>
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1040 <eat@plt>
mov    -0x8(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
call   1060 <cast_expr@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rsi
call   1050 <read_expr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <arithmetic@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <arithmetic_result@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <is_signed@plt>
mov    %eax,-0x3c(%rbp)
movl   $0xffffffff,-0x38(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0xc,%eax
je     1286 <mult_expr+0x106>
jmp    1264 <mult_expr+0xe4>
mov    -0x44(%rbp),%eax
sub    $0x28,%eax
je     12a1 <mult_expr+0x121>
jmp    1275 <mult_expr+0xf5>
mov    -0x44(%rbp),%eax
sub    $0x29,%eax
je     12bc <mult_expr+0x13c>
jmp    12d2 <mult_expr+0x152>
mov    -0x3c(%rbp),%edx
mov    $0x3,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x38(%rbp)
jmp    12d2 <mult_expr+0x152>
mov    -0x3c(%rbp),%edx
mov    $0x5,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x38(%rbp)
jmp    12d2 <mult_expr+0x152>
mov    -0x3c(%rbp),%edx
mov    $0x7,%eax
mov    $0x6,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1090 <triple@plt>
mov    %rax,-0x10(%rbp)
jmp    12fa <mult_expr+0x17a>
movl   $0x1,-0x14(%rbp)
jmp    12ff <mult_expr+0x17f>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1199 <mult_expr+0x19>
mov    -0x10(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mult_expr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <cast_expr@plt>
mov    %rax,%r14
movabs $0x30000001000,%r13
jmp    11cf <mult_expr+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %esi,%esi
test   %eax,%eax
sete   %sil
or     $0x6,%esi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1090 <triple@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <peek@plt>
cmp    $0x29,%eax
ja     1290 <mult_expr+0x110>
mov    %eax,%ebp
mov    %eax,%eax
bt     %rax,%r13
jae    1290 <mult_expr+0x110>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <read_expr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <arithmetic@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <eat@plt>
mov    %rbx,%rdi
call   1060 <cast_expr@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <read_expr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <arithmetic@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <arithmetic_result@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <is_signed@plt>
cmp    $0x29,%ebp
je     11b0 <mult_expr+0x30>
cmp    $0x28,%ebp
je     1280 <mult_expr+0x100>
mov    $0xffffffff,%esi
cmp    $0xc,%ebp
jne    11bb <mult_expr+0x3b>
xor    %esi,%esi
test   %eax,%eax
sete   %sil
or     $0x2,%esi
jmp    11bb <mult_expr+0x3b>
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
test   %eax,%eax
sete   %sil
or     $0x4,%esi
jmp    11bb <mult_expr+0x3b>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.triple = type { i32 }
%struct.compile_state = type { i32 }
%struct.type = type { i32 }
define %struct.triple* @mult_expr(%struct.compile_state* %0) {
%2 = alloca %struct.compile_state*
%3 = alloca %struct.triple*
%4 = alloca i32
%5 = alloca %struct.triple*
%6 = alloca %struct.triple*
%7 = alloca %struct.type*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.compile_state* %0, %struct.compile_state** %2
%11 = load %struct.compile_state*, %struct.compile_state** %2
%12 = call %struct.triple* @cast_expr(%struct.compile_state* %11)
store %struct.triple* %12, %struct.triple** %3
br label %13
13: ; preds = %65, %1
store i32 0, i32* %4
%14 = load %struct.compile_state*, %struct.compile_state** %2
%15 = call i32 @peek(%struct.compile_state* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
switch i32 %16, label %63 [
i32 12, label %17
i32 40, label %17
i32 41, label %17
]
17: ; preds = %13, %13, %13
%18 = load %struct.compile_state*, %struct.compile_state** %2
%19 = load %struct.triple*, %struct.triple** %3
%20 = call %struct.triple* @read_expr(%struct.compile_state* %18, %struct.triple* %19)
store %struct.triple* %20, %struct.triple** %5
%21 = load %struct.compile_state*, %struct.compile_state** %2
%22 = load %struct.triple*, %struct.triple** %5
%23 = call i32 @arithmetic(%struct.compile_state* %21, %struct.triple* %22)
%24 = load %struct.compile_state*, %struct.compile_state** %2
%25 = load i32, i32* %8
%26 = call i32 @eat(%struct.compile_state* %24, i32 %25)
%27 = load %struct.compile_state*, %struct.compile_state** %2
%28 = load %struct.compile_state*, %struct.compile_state** %2
%29 = call %struct.triple* @cast_expr(%struct.compile_state* %28)
%30 = call %struct.triple* @read_expr(%struct.compile_state* %27, %struct.triple* %29)
store %struct.triple* %30, %struct.triple** %6
%31 = load %struct.compile_state*, %struct.compile_state** %2
%32 = load %struct.triple*, %struct.triple** %6
%33 = call i32 @arithmetic(%struct.compile_state* %31, %struct.triple* %32)
%34 = load %struct.compile_state*, %struct.compile_state** %2
%35 = load %struct.triple*, %struct.triple** %5
%36 = load %struct.triple*, %struct.triple** %6
%37 = call %struct.type* @arithmetic_result(%struct.compile_state* %34, %struct.triple* %35, %struct.triple* %36)
store %struct.type* %37, %struct.type** %7
%38 = load %struct.type*, %struct.type** %7
%39 = call i32 @is_signed(%struct.type* %38)
store i32 %39, i32* %10
store i32 -1, i32* %9
%40 = load i32, i32* %8
switch i32 %40, label %56 [
i32 12, label %41
i32 40, label %46
i32 41, label %51
]
41: ; preds = %17
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 2, i32 3
store i32 %45, i32* %9
br label %56
46: ; preds = %17
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 4, i32 5
store i32 %50, i32* %9
br label %56
51: ; preds = %17
%52 = load i32, i32* %10
%53 = icmp ne i32 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 6, i32 7
store i32 %55, i32* %9
br label %56
56: ; preds = %17, %51, %46, %41
%57 = load %struct.compile_state*, %struct.compile_state** %2
%58 = load i32, i32* %9
%59 = load %struct.type*, %struct.type** %7
%60 = load %struct.triple*, %struct.triple** %5
%61 = load %struct.triple*, %struct.triple** %6
%62 = call %struct.triple* @triple(%struct.compile_state* %57, i32 %58, %struct.type* %59, %struct.triple* %60, %struct.triple* %61)
store %struct.triple* %62, %struct.triple** %3
br label %64
63: ; preds = %13
store i32 1, i32* %4
br label %64
64: ; preds = %63, %56
br label %65
65: ; preds = %64
%66 = load i32, i32* %4
%67 = icmp ne i32 %66, 0
%68 = xor i1 %67, true
br i1 %68, label %13, label %69
69: ; preds = %65
%70 = load %struct.triple*, %struct.triple** %3
ret %struct.triple* %70
}

LLVM IR (-O2):
%struct.triple = type { i32 }
%struct.compile_state = type { i32 }
%struct.type = type { i32 }
define %struct.triple* @mult_expr(%struct.compile_state* %0) {
%2 = tail call %struct.triple* @cast_expr(%struct.compile_state* %0)
br label %3
3: ; preds = %24, %1
%4 = phi %struct.triple* [ %2, %1 ], [ %26, %24 ]
%5 = tail call i32 @peek(%struct.compile_state* %0)
switch i32 %5, label %27 [
i32 12, label %6
i32 40, label %6
i32 41, label %6
]
6: ; preds = %3, %3, %3
%7 = tail call %struct.triple* @read_expr(%struct.compile_state* %0, %struct.triple* %4)
%8 = tail call i32 @arithmetic(%struct.compile_state* %0, %struct.triple* %7)
%9 = tail call i32 @eat(%struct.compile_state* %0, i32 %5)
%10 = tail call %struct.triple* @cast_expr(%struct.compile_state* %0)
%11 = tail call %struct.triple* @read_expr(%struct.compile_state* %0, %struct.triple* %10)
%12 = tail call i32 @arithmetic(%struct.compile_state* %0, %struct.triple* %11)
%13 = tail call %struct.type* @arithmetic_result(%struct.compile_state* %0, %struct.triple* %7, %struct.triple* %11)
%14 = tail call i32 @is_signed(%struct.type* %13)
switch i32 %5, label %24 [
i32 12, label %15
i32 40, label %18
i32 41, label %21
]
15: ; preds = %6
%16 = icmp eq i32 %14, 0
%17 = select i1 %16, i32 3, i32 2
br label %24
18: ; preds = %6
%19 = icmp eq i32 %14, 0
%20 = select i1 %19, i32 5, i32 4
br label %24
21: ; preds = %6
%22 = icmp eq i32 %14, 0
%23 = select i1 %22, i32 7, i32 6
br label %24
24: ; preds = %15, %18, %21, %6
%25 = phi i32 [ -1, %6 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ]
%26 = tail call %struct.triple* @triple(%struct.compile_state* %0, i32 %25, %struct.type* %13, %struct.triple* %7, %struct.triple* %11)
br label %3
27: ; preds = %3
ret %struct.triple* %4
}