#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 */

/* Variables and functions */
int /*<<< orphan*/ GB_DMAGetClocksToNextEvent();
int /*<<< orphan*/ GB_PPUGetClocksToNextEvent();
int /*<<< orphan*/ GB_SerialGetClocksToNextEvent();
int /*<<< orphan*/ GB_SoundGetClocksToNextEvent();
int GB_TimersGetClocksToNextEvent();
int min(int, int /*<<< orphan*/);
int GB_ClocksForNextEvent(void) {
  int clocks_to_next_event = GB_TimersGetClocksToNextEvent();
  clocks_to_next_event =
      min(clocks_to_next_event, GB_PPUGetClocksToNextEvent());
  clocks_to_next_event =
      min(clocks_to_next_event, GB_SerialGetClocksToNextEvent());
  clocks_to_next_event =
      min(clocks_to_next_event, GB_DMAGetClocksToNextEvent());
  clocks_to_next_event =
      min(clocks_to_next_event, GB_SoundGetClocksToNextEvent());
  clocks_to_next_event =
      min(clocks_to_next_event, GB_SoundGetClocksToNextEvent());
  return (clocks_to_next_event | 4) & ~3;
}


x86 assembly (clang, -O0):
<GB_ClocksForNextEvent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1080 <GB_TimersGetClocksToNextEvent@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <GB_PPUGetClocksToNextEvent@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <GB_SerialGetClocksToNextEvent@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <GB_DMAGetClocksToNextEvent@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <GB_SoundGetClocksToNextEvent@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <GB_SoundGetClocksToNextEvent@plt>
mov    -0x8(%rbp),%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
or     $0x4,%eax
and    $0xfffffffc,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GB_ClocksForNextEvent>:
push   %rbx
xor    %eax,%eax
call   1080 <GB_TimersGetClocksToNextEvent@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <GB_PPUGetClocksToNextEvent@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <GB_SerialGetClocksToNextEvent@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <GB_DMAGetClocksToNextEvent@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <GB_SoundGetClocksToNextEvent@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <min@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <GB_SoundGetClocksToNextEvent@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <min@plt>
and    $0xfffffff8,%eax
or     $0x4,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @GB_ClocksForNextEvent() {
%1 = alloca i32
%2 = call i32 (...) @GB_TimersGetClocksToNextEvent()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = call i32 (...) @GB_PPUGetClocksToNextEvent()
%5 = call i32 @min(i32 %3, i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i32 (...) @GB_SerialGetClocksToNextEvent()
%8 = call i32 @min(i32 %6, i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = call i32 (...) @GB_DMAGetClocksToNextEvent()
%11 = call i32 @min(i32 %9, i32 %10)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = call i32 (...) @GB_SoundGetClocksToNextEvent()
%14 = call i32 @min(i32 %12, i32 %13)
store i32 %14, i32* %1
%15 = load i32, i32* %1
%16 = call i32 (...) @GB_SoundGetClocksToNextEvent()
%17 = call i32 @min(i32 %15, i32 %16)
store i32 %17, i32* %1
%18 = load i32, i32* %1
%19 = or i32 %18, 4
%20 = and i32 %19, -4
ret i32 %20
}

LLVM IR (-O2):
define i32 @GB_ClocksForNextEvent() {
%1 = tail call i32 (...) @GB_TimersGetClocksToNextEvent()
%2 = tail call i32 (...) @GB_PPUGetClocksToNextEvent()
%3 = tail call i32 @min(i32 %1, i32 %2)
%4 = tail call i32 (...) @GB_SerialGetClocksToNextEvent()
%5 = tail call i32 @min(i32 %3, i32 %4)
%6 = tail call i32 (...) @GB_DMAGetClocksToNextEvent()
%7 = tail call i32 @min(i32 %5, i32 %6)
%8 = tail call i32 (...) @GB_SoundGetClocksToNextEvent()
%9 = tail call i32 @min(i32 %7, i32 %8)
%10 = tail call i32 (...) @GB_SoundGetClocksToNextEvent()
%11 = tail call i32 @min(i32 %9, i32 %10)
%12 = and i32 %11, -8
%13 = or i32 %12, 4
ret i32 %13
}