#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 expr {
  int dummy;
};
typedef void FunctionDefinition;

/* Variables and functions */
void *FindFunction(void *, char const *);
struct expr *GenConstant(void *, int, void *);
scalar_t__ LookupDeffunctionInScope(void *, char const *);
scalar_t__ LookupDefgenericInScope(void *, char const *);
struct expr *FunctionReferenceExpression(void *theEnv, const char *name) {
  void *gfunc;
  void *dptr;
  struct FunctionDefinition *fptr;
  if ((dptr = (void *)LookupDeffunctionInScope(theEnv, name)) != NULL) {
    return (GenConstant(theEnv, 32, dptr));
  }
  if ((gfunc = (void *)LookupDefgenericInScope(theEnv, name)) != NULL) {
    return (GenConstant(theEnv, 31, gfunc));
  }
  if ((fptr = FindFunction(theEnv, name)) != NULL) {
    return (GenConstant(theEnv, 30, fptr));
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<FunctionReferenceExpression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <LookupDeffunctionInScope@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1186 <FunctionReferenceExpression+0x46>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x20,%esi
call   1030 <GenConstant@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <FunctionReferenceExpression+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <LookupDefgenericInScope@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11bc <FunctionReferenceExpression+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1f,%esi
call   1030 <GenConstant@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <FunctionReferenceExpression+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <FindFunction@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11f2 <FunctionReferenceExpression+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x1e,%esi
call   1030 <GenConstant@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <FunctionReferenceExpression+0xba>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FunctionReferenceExpression>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <LookupDeffunctionInScope@plt>
test   %rax,%rax
je     115e <FunctionReferenceExpression+0x1e>
mov    %rbx,%rdi
mov    $0x20,%esi
jmp    1190 <FunctionReferenceExpression+0x50>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <LookupDefgenericInScope@plt>
test   %rax,%rax
je     1178 <FunctionReferenceExpression+0x38>
mov    %rbx,%rdi
mov    $0x1f,%esi
jmp    1190 <FunctionReferenceExpression+0x50>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <FindFunction@plt>
test   %rax,%rax
je     119f <FunctionReferenceExpression+0x5f>
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <GenConstant@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.expr = type { i32 }
%struct.FunctionDefinition = type opaque
define %struct.expr* @FunctionReferenceExpression(i8* %0, i8* %1) {
%3 = alloca %struct.expr*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.FunctionDefinition*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i64 @LookupDeffunctionInScope(i8* %9, i8* %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %7
%17 = call %struct.expr* @GenConstant(i8* %15, i32 32, i8* %16)
store %struct.expr* %17, %struct.expr** %3
br label %40
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i64 @LookupDefgenericInScope(i8* %19, i8* %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = load i8*, i8** %6
%27 = call %struct.expr* @GenConstant(i8* %25, i32 31, i8* %26)
store %struct.expr* %27, %struct.expr** %3
br label %40
28: ; preds = %18
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i8* @FindFunction(i8* %29, i8* %30)
%32 = bitcast i8* %31 to %struct.FunctionDefinition*
store %struct.FunctionDefinition* %32, %struct.FunctionDefinition** %8
%33 = icmp ne %struct.FunctionDefinition* %32, null
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i8*, i8** %4
%36 = load %struct.FunctionDefinition*, %struct.FunctionDefinition** %8
%37 = bitcast %struct.FunctionDefinition* %36 to i8*
%38 = call %struct.expr* @GenConstant(i8* %35, i32 30, i8* %37)
store %struct.expr* %38, %struct.expr** %3
br label %40
39: ; preds = %28
store %struct.expr* null, %struct.expr** %3
br label %40
40: ; preds = %39, %34, %24, %14
%41 = load %struct.expr*, %struct.expr** %3
ret %struct.expr* %41
}

LLVM IR (-O2):
%struct.expr = type { i32 }
define %struct.expr* @FunctionReferenceExpression(i8* %0, i8* %1) {
%3 = tail call i64 @LookupDeffunctionInScope(i8* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = inttoptr i64 %3 to i8*
%7 = tail call %struct.expr* @GenConstant(i8* %0, i32 32, i8* %6)
br label %19
8: ; preds = %2
%9 = tail call i64 @LookupDefgenericInScope(i8* %0, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = inttoptr i64 %9 to i8*
%13 = tail call %struct.expr* @GenConstant(i8* %0, i32 31, i8* %12)
br label %19
14: ; preds = %8
%15 = tail call i8* @FindFunction(i8* %0, i8* %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call %struct.expr* @GenConstant(i8* %0, i32 30, i8* %15)
br label %19
19: ; preds = %14, %17, %11, %5
%20 = phi %struct.expr* [ %7, %5 ], [ %13, %11 ], [ %18, %17 ], [ null, %14 ]
ret %struct.expr* %20
}