#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 *luaL_opt_string(int, char *);
int /*<<< orphan*/ lua_error(char *);
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 = luaL_opt_string(1, "%c");
  char b[BUFSIZ];
  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
lea    0xe91(%rip),%rsi
mov    $0x1,%edi
call   1050 <luaL_opt_string@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%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,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x4(%rbp),%rdi
call   1040 <time@plt>
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,-0x10(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1070 <strftime@plt>
cmp    $0x0,%rax
je     11f5 <io_date+0x95>
mov    -0x38(%rbp),%rdi
call   1080 <lua_pushstring@plt>
jmp    1201 <io_date+0xa1>
lea    0xe07(%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
lea    0xe8b(%rip),%rsi
mov    $0x1,%edi
call   1050 <luaL_opt_string@plt>
mov    %rax,%r14
mov    %rsp,%r13
mov    0x2e54(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x2c(%rbp),%r12
mov    %r12,%rdi
call   1040 <time@plt>
mov    %r12,%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %rax,%rax
je     11d7 <io_date+0x77>
mov    %rbx,%rdi
call   1080 <lua_pushstring@plt>
jmp    11e3 <io_date+0x83>
lea    0xe25(%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 }
@.str = [3 x i8] c"%c\00"
@BUFSIZ = global i32 0
@.str.1 = [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 = call i8* @luaL_opt_string(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8, i64 %8
store i64 %8, i64* %5
%11 = call i32 @time(i32* %1)
%12 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %12, %struct.tm** %2
%13 = trunc i64 %8 to i32
%14 = load i8*, i8** %3
%15 = load %struct.tm*, %struct.tm** %2
%16 = call i64 @strftime(i8* %10, i32 %13, i8* %14, %struct.tm* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @lua_pushstring(i8* %10)
br label %22
20: ; preds = %0
%21 = call i32 @lua_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = load i8*, i8** %4
ret void
}

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