#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*/ assert(int);
int /*<<< orphan*/ get_localtime(int /*<<< orphan*/ *, struct tm *);
int strftime(char *, size_t, char *, struct tm *);
int write_time_string(time_t t, char *dst, size_t dstlen) {
  struct tm tm;
  int n;
  if (dstlen <= 20) {
    return (0);
  }
  get_localtime(&t, &tm);
  if (!(n = strftime(dst, dstlen, "%Y-%m-%d %H:%M:%S ", &tm))) {
    return (0);
  }
  assert(n == 20);
  return (n);
}


x86 assembly (clang, -O0):
<write_time_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x14,-0x18(%rbp)
ja     115a <write_time_string+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11ae <write_time_string+0x7e>
lea    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <get_localtime@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe8a(%rip),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <strftime@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    1197 <write_time_string+0x67>
movl   $0x0,-0x4(%rbp)
jmp    11ae <write_time_string+0x7e>
cmpl   $0x14,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_time_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,0xc(%rsp)
xor    %ebp,%ebp
cmp    $0x15,%rdx
jb     1189 <write_time_string+0x59>
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
call   1050 <get_localtime@plt>
lea    0xe9b(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
call   1040 <strftime@plt>
test   %eax,%eax
je     1189 <write_time_string+0x59>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0x14,%eax
sete   %dil
call   1030 <assert@plt>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [19 x i8] c"%Y-%m-%d %H:%M:%S \00"
define i32 @write_time_string(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.tm
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i64, i64* %7
%11 = icmp ule i64 %10, 20
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %26
13: ; preds = %3
%14 = call i32 @get_localtime(i32* %5, %struct.tm* %8)
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = call i32 @strftime(i8* %15, i64 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
store i32 %17, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %13
store i32 0, i32* %4
br label %26
20: ; preds = %13
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 20
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* %9
store i32 %25, i32* %4
br label %26
26: ; preds = %20, %19, %12
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [19 x i8] c"%Y-%m-%d %H:%M:%S \00"
define i32 @write_time_string(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %0, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = icmp ult i64 %2, 21
br i1 %7, label %16, label %8
8: ; preds = %3
%9 = call i32 @get_localtime(i32* %4, %struct.tm* %5)
%10 = call i32 @strftime(i8* %1, i64 %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %struct.tm* %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = icmp eq i32 %10, 20
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
br label %16
16: ; preds = %8, %3, %12
%17 = phi i32 [ %10, %12 ], [ 0, %3 ], [ 0, %8 ]
ret i32 %17
}