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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
char *time_str(char *buf) {
  struct timeval tv;
  struct tm gmt;
  gettimeofday(&tv, NULL);
  gmtime_r(&tv.tv_sec, &gmt);
  sprintf(buf, "%d:%d:%d", gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
  return buf;
}


x86 assembly (clang, -O0):
<time_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <gmtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe95(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_str>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <gmtime_r@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [9 x i8] c"%d:%d:%d\00"
define i8* @time_str(i8* returned writeonly %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 0
%8 = call i32 @gmtime_r(i32* %7, %struct.tm* %3)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%14 = load i32, i32* %13
%15 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %12, i32 %14)
ret i8* %0
}