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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
const char *getcurrenttime(char *str) {
  struct timeval tv;
  struct timezone tz;
  struct tm *tm;
  gettimeofday(&tv, &tz);
  tm = localtime(&tv.tv_sec);
  sprintf(str, "%d:%02d:%02d.%d", tm->tm_hour, tm->tm_min, tm->tm_sec,
          tv.tv_usec);
  return str;
}


x86 assembly (clang, -O0):
<getcurrenttime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x10(%rbp),%r9d
lea    0xe82(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcurrenttime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1040 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
mov    (%rsp),%r9d
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [16 x i8] c"%d:%02d:%02d.%d\00"
define i8* @getcurrenttime(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = alloca %struct.tm*
store i8* %0, i8** %2
%6 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%8 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %8, %struct.tm** %5
%9 = load i8*, i8** %2
%10 = load %struct.tm*, %struct.tm** %5
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load %struct.tm*, %struct.tm** %5
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.tm*, %struct.tm** %5
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %15, i32 %18, i32 %20)
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [16 x i8] c"%d:%02d:%02d.%d\00"
define i8* @getcurrenttime(i8* returned writeonly %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = call %struct.tm* @localtime(i32* %7)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %12, i32 %14, i32 %16)
ret i8* %0
}