#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 dummy;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, size_t, char *, struct tm *);
int strlen(char *);
char *print_time(char *buf, size_t size) {
  struct timeval tv;
  struct tm *tm;
  if (gettimeofday(&tv, NULL))
    return NULL;
  tm = localtime(&tv.tv_sec);
  if (!tm)
    return NULL;
  if (!strftime(buf, size, "%a %b %e %Y %H:%M:%S", tm))
    return NULL;
  sprintf(buf + strlen(buf), ".%06ld", tv.tv_usec);
  return buf;
}


x86 assembly (clang, -O0):
<print_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     1184 <print_time+0x34>
movq   $0x0,-0x8(%rbp)
jmp    120c <print_time+0xbc>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ad <print_time+0x5d>
movq   $0x0,-0x8(%rbp)
jmp    120c <print_time+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe40(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%eax
jne    11db <print_time+0x8b>
movq   $0x0,-0x8(%rbp)
jmp    120c <print_time+0xbc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%edx
lea    0xe16(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    11bf <print_time+0x6f>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11bd <print_time+0x6d>
lea    0xe78(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %eax,%eax
je     11bd <print_time+0x6d>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
mov    0x8(%rsp),%edx
lea    0xe62(%rip),%rsi
call   1070 <sprintf@plt>
mov    %r14,%rbx
jmp    11bf <print_time+0x6f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [21 x i8] c"%a %b %e %Y %H:%M:%S\00"
@.str.1 = [7 x i8] c".%06ld\00"
define i8* @print_time(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.timeval
%7 = alloca %struct.tm*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %34
11: ; preds = %2
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%13 = call %struct.tm* @localtime(i32* %12)
store %struct.tm* %13, %struct.tm** %7
%14 = load %struct.tm*, %struct.tm** %7
%15 = icmp ne %struct.tm* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
store i8* null, i8** %3
br label %34
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = load %struct.tm*, %struct.tm** %7
%21 = call i32 @strftime(i8* %18, i64 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %struct.tm* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17
store i8* null, i8** %3
br label %34
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %4
store i8* %33, i8** %3
br label %34
34: ; preds = %24, %23, %16, %10
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [21 x i8] c"%a %b %e %Y %H:%M:%S\00"
@.str.1 = [7 x i8] c".%06ld\00"
define i8* @print_time(i8* %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = call %struct.tm* @localtime(i32* %8)
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = call i32 @strftime(i8* %0, i64 %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = call i32 @strlen(i8* %0)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %11, %7, %2, %14
%22 = phi i8* [ %0, %14 ], [ null, %2 ], [ null, %7 ], [ null, %11 ]
ret i8* %22
}