#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;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int getDateTime(char *buf, int buf_size) {
  time_t ts;
  struct tm *tm;
  int len;
  ts = time(NULL);
  tm = localtime(&ts);
  len = strftime(buf, buf_size - 1, "%a, %b %d %H:%M:%S", tm);
  if (!len) {
    fprintf(stderr, "strftime return 0\n");
    return 0;
  }
  return len;
}


x86 assembly (clang, -O0):
<getDateTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%rcx
lea    0xe83(%rip),%rdx
call   1060 <strftime@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11b0 <getDateTime+0x70>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <getDateTime+0x76>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDateTime>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
add    $0xffffffff,%ebx
lea    0xe98(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1190 <getDateTime+0x50>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [19 x i8] c"%a, %b %d %H:%M:%S\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"strftime return 0\0A\00"
define i32 @getDateTime(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = call i32 @time(i32* null)
store i32 %9, i32* %6
%10 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %10, %struct.tm** %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = sub nsw i32 %12, 1
%14 = load %struct.tm*, %struct.tm** %7
%15 = call i32 @strftime(i8* %11, i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %23
21: ; preds = %2
%22 = load i32, i32* %8
store i32 %22, i32* %3
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [19 x i8] c"%a, %b %d %H:%M:%S\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"strftime return 0\0A\00"
define i32 @getDateTime(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %3
%6 = call %struct.tm* @localtime(i32* %3)
%7 = add nsw i32 %1, -1
%8 = call i32 @strftime(i8* %0, i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %2, %10
ret i32 %8
}