#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 defmoduleItemHeader {
  int dummy;
};
struct defmodule {
  int dummy;
};

/* Variables and functions */
scalar_t__ EnvGetCurrentModule(void *);
scalar_t__ GetModuleItem(void *, struct defmodule *, int);
struct defmoduleItemHeader *
GetConstructModuleItemByIndex(void *theEnv, struct defmodule *theModule,
                              int moduleIndex) {
  if (theModule != NULL) {
    return ((struct defmoduleItemHeader *)GetModuleItem(theEnv, theModule,
                                                        moduleIndex));
  }
  return ((struct defmoduleItemHeader *)GetModuleItem(
      theEnv, ((struct defmodule *)EnvGetCurrentModule(theEnv)), moduleIndex));
}


x86 assembly (clang, -O0):
<GetConstructModuleItemByIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1157 <GetConstructModuleItemByIndex+0x37>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <GetModuleItem@plt>
mov    %rax,-0x8(%rbp)
jmp    117b <GetConstructModuleItemByIndex+0x5b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <EnvGetCurrentModule@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1040 <GetModuleItem@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetConstructModuleItemByIndex>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
test   %rsi,%rsi
je     1132 <GetConstructModuleItemByIndex+0x12>
mov    %rbx,%rdi
jmp    1140 <GetConstructModuleItemByIndex+0x20>
mov    %rbx,%rdi
call   1030 <EnvGetCurrentModule@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1040 <GetModuleItem@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.defmoduleItemHeader = type { i32 }
%struct.defmodule = type { i32 }
define %struct.defmoduleItemHeader* @GetConstructModuleItemByIndex(i8* %0, %struct.defmodule* %1, i32 %2) {
%4 = alloca %struct.defmoduleItemHeader*
%5 = alloca i8*
%6 = alloca %struct.defmodule*
%7 = alloca i32
store i8* %0, i8** %5
store %struct.defmodule* %1, %struct.defmodule** %6
store i32 %2, i32* %7
%8 = load %struct.defmodule*, %struct.defmodule** %6
%9 = icmp ne %struct.defmodule* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = load %struct.defmodule*, %struct.defmodule** %6
%13 = load i32, i32* %7
%14 = call i64 @GetModuleItem(i8* %11, %struct.defmodule* %12, i32 %13)
%15 = inttoptr i64 %14 to %struct.defmoduleItemHeader*
store %struct.defmoduleItemHeader* %15, %struct.defmoduleItemHeader** %4
br label %24
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i8*, i8** %5
%19 = call i64 @EnvGetCurrentModule(i8* %18)
%20 = inttoptr i64 %19 to %struct.defmodule*
%21 = load i32, i32* %7
%22 = call i64 @GetModuleItem(i8* %17, %struct.defmodule* %20, i32 %21)
%23 = inttoptr i64 %22 to %struct.defmoduleItemHeader*
store %struct.defmoduleItemHeader* %23, %struct.defmoduleItemHeader** %4
br label %24
24: ; preds = %16, %10
%25 = load %struct.defmoduleItemHeader*, %struct.defmoduleItemHeader** %4
ret %struct.defmoduleItemHeader* %25
}

LLVM IR (-O2):
%struct.defmoduleItemHeader = type { i32 }
%struct.defmodule = type { i32 }
define %struct.defmoduleItemHeader* @GetConstructModuleItemByIndex(i8* %0, %struct.defmodule* %1, i32 %2) {
%4 = icmp eq %struct.defmodule* %1, null
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i64 @GetModuleItem(i8* %0, %struct.defmodule* %1, i32 %2)
br label %11
7: ; preds = %3
%8 = tail call i64 @EnvGetCurrentModule(i8* %0)
%9 = inttoptr i64 %8 to %struct.defmodule*
%10 = tail call i64 @GetModuleItem(i8* %0, %struct.defmodule* %9, i32 %2)
br label %11
11: ; preds = %7, %5
%12 = phi i64 [ %6, %5 ], [ %10, %7 ]
%13 = inttoptr i64 %12 to %struct.defmoduleItemHeader*
ret %struct.defmoduleItemHeader* %13
}