#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 */
double luaL_check_number(int);
scalar_t__ lua_lua2C(int);
int /*<<< orphan*/ lua_pushnumber(double);
void math_max(void) {
  int i = 1;
  double dmax = luaL_check_number(i);
  while (lua_lua2C(++i) != 0) {
    double d = luaL_check_number(i);
    if (d > dmax)
      dmax = d;
  }
  lua_pushnumber(dmax);
}


x86 assembly (clang, -O0):
<math_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <luaL_check_number@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    %edi,-0x4(%rbp)
call   1050 <lua_lua2C@plt>
cmp    $0x0,%rax
je     1190 <math_max+0x60>
mov    -0x4(%rbp),%edi
call   1030 <luaL_check_number@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118b <math_max+0x5b>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    114c <math_max+0x1c>
movsd  -0x10(%rbp),%xmm0
call   1040 <lua_pushnumber@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_max>:
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
call   1030 <luaL_check_number@plt>
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
call   1050 <lua_lua2C@plt>
test   %rax,%rax
je     118f <math_max+0x5f>
mov    $0x3,%ebx
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%edi
call   1030 <luaL_check_number@plt>
maxsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1050 <lua_lua2C@plt>
movsd  0x8(%rsp),%xmm0
add    $0x1,%ebx
movsd  %xmm0,(%rsp)
test   %rax,%rax
jne    1160 <math_max+0x30>
jmp    1194 <math_max+0x64>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
jmp    1040 <lua_pushnumber@plt>

LLVM IR (-O0):
define void @math_max() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
store i32 1, i32* %1
%4 = load i32, i32* %1
%5 = call double @luaL_check_number(i32 %4)
store double %5, double* %2
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %1
%8 = add nsw i32 %7, 1
store i32 %8, i32* %1
%9 = call i64 @lua_lua2C(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = load i32, i32* %1
%13 = call double @luaL_check_number(i32 %12)
store double %13, double* %3
%14 = load double, double* %3
%15 = load double, double* %2
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load double, double* %3
store double %18, double* %2
br label %19
19: ; preds = %17, %11
br label %6
20: ; preds = %6
%21 = load double, double* %2
%22 = call i32 @lua_pushnumber(double %21)
ret void
}

LLVM IR (-O2):
define void @math_max() {
%1 = tail call double @luaL_check_number(i32 1)
%2 = tail call i64 @lua_lua2C(i32 2)
%3 = icmp eq i64 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %0, %4
%5 = phi i32 [ %10, %4 ], [ 2, %0 ]
%6 = phi double [ %9, %4 ], [ %1, %0 ]
%7 = tail call double @luaL_check_number(i32 %5)
%8 = fcmp ogt double %7, %6
%9 = select i1 %8, double %7, double %6
%10 = add nuw nsw i32 %5, 1
%11 = tail call i64 @lua_lua2C(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4, %0
%14 = phi double [ %1, %0 ], [ %9, %4 ]
%15 = tail call i32 @lua_pushnumber(double %14)
ret void
}