#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 timeval {
  int tv_usec;
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
char *debugtime(char *str) {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  int ms = tv.tv_usec / 1000;
  int hr = (1 + (tv.tv_sec / 3600)) % 24;
  int mn = (tv.tv_sec % 3600) / 60;
  int sd = (tv.tv_sec % 60);
  sprintf(str, "[%02d:%02d:%02d.%03d]", hr, mn, sd, ms);
  return str;
}


x86 assembly (clang, -O0):
<debugtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    0xe61(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debugtime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0x10624dd3,%rax,%r9
mov    %r9,%rax
shr    $0x3f,%rax
shr    $0x20,%r9
sar    $0x6,%r9d
add    %eax,%r9d
movslq 0xc(%rsp),%r8
imul   $0xffffffff91a2b3c5,%r8,%rax
shr    $0x20,%rax
add    %r8d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0xb,%eax
lea    (%rax,%rcx,1),%edx
add    $0x1,%edx
movslq %edx,%rdx
imul   $0x2aaaaaab,%rdx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
shr    $0x22,%rsi
add    %edi,%esi
shl    $0x3,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%edx
add    %ecx,%eax
imul   $0xe10,%eax,%eax
mov    %r8d,%ecx
sub    %eax,%ecx
movswl %cx,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %ecx,%eax
movzwl %ax,%eax
movswl %ax,%ecx
shr    $0xf,%eax
sar    $0x5,%ecx
add    %eax,%ecx
movswl %cx,%ecx
imul   $0xffffffff88888889,%r8,%rax
shr    $0x20,%rax
add    %r8d,%eax
mov    %eax,%esi
shr    $0x1f,%esi
sar    $0x5,%eax
add    %esi,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%r8d
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [22 x i8] c"[%02d:%02d:%02d.%03d]\00"
define i8* @debugtime(i8* returned writeonly %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = sdiv i32 %6, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 3600
%11 = add nsw i32 %10, 1
%12 = srem i32 %11, 24
%13 = srem i32 %9, 3600
%14 = trunc i32 %13 to i16
%15 = sdiv i16 %14, 60
%16 = sext i16 %15 to i32
%17 = srem i32 %9, 60
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %16, i32 %17, i32 %7)
ret i8* %0
}