#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 */
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int snprintf(char *, int, char *, int, int, int, int, int, int, int);
int current_time(char buf[32]) {
  struct timeval tv;
  struct tm tm;
  int r;
  gettimeofday(&tv, NULL);
  localtime_r(&tv.tv_sec, &tm);
  r = snprintf(buf, 32, "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
               tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
               tm.tm_min, tm.tm_sec, tv.tv_usec / 1000);
  return r <= 0;
}


x86 assembly (clang, -O0):
<current_time>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x18(%rbp),%rdi
add    $0x4,%rdi
lea    -0x30(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x2c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x28(%rbp),%r9d
mov    -0x24(%rbp),%ebx
mov    -0x20(%rbp),%r11d
mov    -0x1c(%rbp),%r10d
mov    -0x18(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    $0x20,%esi
lea    0xe6a(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_time>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    $0x76c,%ecx
add    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
add    $0x1,%r8d
mov    0x1c(%rsp),%r10d
mov    0x20(%rsp),%r11d
mov    0x24(%rsp),%eax
movslq 0x8(%rsp),%rdx
imul   $0x10624dd3,%rdx,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rbx
add    %edx,%ebx
lea    0xe66(%rip),%rdx
mov    %r14,%rdi
mov    $0x20,%esi
push   %rbx
push   %rax
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
xor    %ecx,%ecx
test   %eax,%eax
setle  %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [36 x i8] c"%04d-%02d-%02d %02d:%02d:%02d.%03ld\00"
define i32 @current_time(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%8 = call i32 @localtime_r(i32* %7, %struct.tm* %4)
%9 = load i8*, i8** %2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1900
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%25 = load i32, i32* %24
%26 = sdiv i32 %25, 1000
%27 = call i32 @snprintf(i8* %9, i32 32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23, i32 %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp sle i32 %28, 0
%30 = zext i1 %29 to i32
ret i32 %30
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [36 x i8] c"%04d-%02d-%02d %02d:%02d:%02d.%03ld\00"
define i32 @current_time(i8* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.tm
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.tm* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = call i32 @localtime_r(i32* %7, %struct.tm* %3)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1900
%12 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
%15 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = sdiv i32 %24, 1000
%26 = call i32 @snprintf(i8* %0, i32 32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14, i32 %16, i32 %18, i32 %20, i32 %22, i32 %25)
%27 = icmp slt i32 %26, 1
%28 = zext i1 %27 to i32
ret i32 %28
}