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

/* Variables and functions */
struct triple *deref_index(struct compile_state *, struct triple *, int);
struct triple *fresult(struct compile_state *, struct triple *);
struct triple *closure_expr(struct compile_state *state, struct triple *func,
                            int closure_idx, int var_idx) {
  return deref_index(state,
                     deref_index(state,
                                 deref_index(state, fresult(state, func), 0),
                                 closure_idx),
                     var_idx);
}


x86 assembly (clang, -O0):
<closure_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fresult@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1030 <deref_index@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <deref_index@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <deref_index@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closure_expr>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rdi,%rbx
call   1040 <fresult@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1030 <deref_index@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <deref_index@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <deref_index@plt>

LLVM IR (-O0):
%struct.compile_state = type { i32 }
%struct.triple = type { i32 }
define %struct.triple* @closure_expr(%struct.compile_state* %0, %struct.triple* %1, i32 %2, i32 %3) {
%5 = alloca %struct.compile_state*
%6 = alloca %struct.triple*
%7 = alloca i32
%8 = alloca i32
store %struct.compile_state* %0, %struct.compile_state** %5
store %struct.triple* %1, %struct.triple** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load %struct.compile_state*, %struct.compile_state** %5
%10 = load %struct.compile_state*, %struct.compile_state** %5
%11 = load %struct.compile_state*, %struct.compile_state** %5
%12 = load %struct.compile_state*, %struct.compile_state** %5
%13 = load %struct.triple*, %struct.triple** %6
%14 = call %struct.triple* @fresult(%struct.compile_state* %12, %struct.triple* %13)
%15 = call %struct.triple* @deref_index(%struct.compile_state* %11, %struct.triple* %14, i32 0)
%16 = load i32, i32* %7
%17 = call %struct.triple* @deref_index(%struct.compile_state* %10, %struct.triple* %15, i32 %16)
%18 = load i32, i32* %8
%19 = call %struct.triple* @deref_index(%struct.compile_state* %9, %struct.triple* %17, i32 %18)
ret %struct.triple* %19
}

LLVM IR (-O2):
%struct.compile_state = type { i32 }
%struct.triple = type { i32 }
define %struct.triple* @closure_expr(%struct.compile_state* %0, %struct.triple* %1, i32 %2, i32 %3) {
%5 = tail call %struct.triple* @fresult(%struct.compile_state* %0, %struct.triple* %1)
%6 = tail call %struct.triple* @deref_index(%struct.compile_state* %0, %struct.triple* %5, i32 0)
%7 = tail call %struct.triple* @deref_index(%struct.compile_state* %0, %struct.triple* %6, i32 %2)
%8 = tail call %struct.triple* @deref_index(%struct.compile_state* %0, %struct.triple* %7, i32 %3)
ret %struct.triple* %8
}