#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ b;

/* Variables and functions */
int BUFSIZ;
struct tm *localtime(int /*<<< orphan*/ *);
char *lua_check_string(int, char *);
int /*<<< orphan*/ lua_error(char *);
scalar_t__ lua_getparam(int);
int /*<<< orphan*/ lua_pushstring(char *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void io_date(void) {
  time_t t;
  struct tm *tm;
  char *s;
  char b[BUFSIZ];
  if (lua_getparam(1) == 0)
    s = "%c";
  else
    s = lua_check_string(1, "date");
  time(&t);
  tm = localtime(&t);
  if (strftime(b, sizeof(b), s, tm))
    lua_pushstring(b);
  else
    lua_error("invalid `date' format");
}


x86 assembly (clang, -O0):
<io_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    $0x1,%edi
call   1070 <lua_getparam@plt>
cmp    $0x0,%rax
jne    11cc <io_date+0x5c>
lea    0xe3d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11e1 <io_date+0x71>
mov    $0x1,%edi
lea    0xe2b(%rip),%rsi
call   1040 <lua_check_string@plt>
mov    %rax,-0x18(%rbp)
lea    -0x4(%rbp),%rdi
call   1050 <time@plt>
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,-0x10(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1080 <strftime@plt>
cmp    $0x0,%rax
je     1229 <io_date+0xb9>
mov    -0x30(%rbp),%rdi
call   1090 <lua_pushstring@plt>
jmp    1235 <io_date+0xc5>
lea    0xdd8(%rip),%rdi
call   1060 <lua_error@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_date>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsp,%r13
mov    0x2e58(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    $0x1,%edi
call   1070 <lua_getparam@plt>
test   %rax,%rax
je     11c4 <io_date+0x54>
lea    0xe4e(%rip),%rsi
mov    $0x1,%edi
call   1040 <lua_check_string@plt>
mov    %rax,%r15
jmp    11cb <io_date+0x5b>
lea    0xe35(%rip),%r15
lea    -0x2c(%rbp),%r12
mov    %r12,%rdi
call   1050 <time@plt>
mov    %r12,%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1080 <strftime@plt>
test   %rax,%rax
je     11ff <io_date+0x8f>
mov    %rbx,%rdi
call   1090 <lua_pushstring@plt>
jmp    120b <io_date+0x9b>
lea    0xe02(%rip),%rdi
call   1060 <lua_error@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"date\00"
@.str.2 = [22 x i8] c"invalid `date' format\00"
define void @io_date() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
%10 = call i64 @lua_getparam(i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
br label %15
13: ; preds = %0
%14 = call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %3
br label %15
15: ; preds = %13, %12
%16 = call i32 @time(i32* %1)
%17 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %17, %struct.tm** %2
%18 = trunc i64 %7 to i32
%19 = load i8*, i8** %3
%20 = load %struct.tm*, %struct.tm** %2
%21 = call i64 @strftime(i8* %9, i32 %18, i8* %19, %struct.tm* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @lua_pushstring(i8* %9)
br label %27
25: ; preds = %15
%26 = call i32 @lua_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"date\00"
@.str.2 = [22 x i8] c"invalid `date' format\00"
define void @io_date() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca i8, i64 %4
%7 = tail call i64 @lua_getparam(i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = tail call i8* @lua_check_string(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %0, %9
%12 = phi i8* [ %10, %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %0 ]
%13 = call i32 @time(i32* %1)
%14 = call %struct.tm* @localtime(i32* %1)
%15 = call i64 @strftime(i8* %6, i32 %3, i8* %12, %struct.tm* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = call i32 @lua_pushstring(i8* %6)
br label %21
19: ; preds = %11
%20 = call i32 @lua_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
ret void
}