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

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ trim_end_lf(char *);
void get_time_now_string(char now_str[], size_t len) {
  time_t t;
  char *now_str_ptr;
  size_t now_str_len;
  t = time(NULL);
  now_str_ptr = ctime(&t);
  now_str_len = strlen(now_str_ptr);
  if (len > now_str_len) {
    strncpy(now_str, now_str_ptr, now_str_len);
    now_str[now_str_len] = '\0';
  } else {
    strncpy(now_str, now_str_ptr, len - 1);
    now_str[len - 1] = '\0';
  }
  trim_end_lf(now_str);
}


x86 assembly (clang, -O0):
<get_time_now_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <ctime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11b6 <get_time_now_string+0x66>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11db <get_time_now_string+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1040 <trim_end_lf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_now_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1050 <ctime@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <strlen@plt>
lea    -0x1(%r14),%rbx
cmp    %r14,%rax
cmovb  %rax,%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
call   1040 <trim_end_lf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @get_time_now_string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = call i32 @time(i32* null)
store i32 %8, i32* %5
%9 = call i8* @ctime(i32* %5)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %7
%12 = load i64, i64* %4
%13 = load i64, i64* %7
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = call i32 @strncpy(i8* %16, i8* %17, i64 %18)
%20 = load i8*, i8** %3
%21 = load i64, i64* %7
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 0, i8* %22
br label %33
23: ; preds = %2
%24 = load i8*, i8** %3
%25 = load i8*, i8** %6
%26 = load i64, i64* %4
%27 = sub i64 %26, 1
%28 = call i32 @strncpy(i8* %24, i8* %25, i64 %27)
%29 = load i8*, i8** %3
%30 = load i64, i64* %4
%31 = sub i64 %30, 1
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %23, %15
%34 = load i8*, i8** %3
%35 = call i32 @trim_end_lf(i8* %34)
ret void
}

LLVM IR (-O2):
define void @get_time_now_string(i8* %0, i64 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %3
%6 = call i8* @ctime(i32* %3)
%7 = call i64 @strlen(i8* dereferenceable(1) %6)
%8 = icmp ult i64 %7, %1
%9 = add i64 %1, -1
%10 = select i1 %8, i64 %7, i64 %9
%11 = call i32 @strncpy(i8* %0, i8* %6, i64 %10)
%12 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %12
%13 = call i32 @trim_end_lf(i8* %0)
ret void
}