#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 */
scalar_t__ asctime_r(struct tm *, char *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void get_date(char *buf) {
  struct tm curtime;
  time_t ltime;
  ltime = time(&ltime);
  localtime_r(&ltime, &curtime);
  if (asctime_r(&curtime, buf) == 0) {
    buf[0] = 0;
    return;
  }
  buf[strlen(buf) - 1] = 0;
}


x86 assembly (clang, -O0):
<get_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1060 <asctime_r@plt>
cmp    $0x0,%rax
jne    1188 <get_date+0x48>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11a9 <get_date+0x69>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_date>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <localtime_r@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <asctime_r@plt>
test   %rax,%rax
je     118e <get_date+0x4e>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
movb   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define void @get_date(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 @time(i32* %4)
store i32 %5, i32* %4
%6 = call i32 @localtime_r(i32* %4, %struct.tm* %3)
%7 = load i8*, i8** %2
%8 = call i64 @asctime_r(%struct.tm* %3, i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
br label %20
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %13, %10
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define void @get_date(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = bitcast %struct.tm* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @time(i32* %3)
store i32 %6, i32* %3
%7 = call i32 @localtime_r(i32* %3, %struct.tm* %2)
%8 = call i64 @asctime_r(%struct.tm* %2, i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
br label %15
15: ; preds = %1, %10
%16 = phi i8* [ %14, %10 ], [ %0, %1 ]
store i8 0, i8* %16
ret void
}