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

/* Variables and functions */
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void printt(void) {
  struct timeval tv;
  struct tm *lt;
  time_t t = gettimeofday(&tv, NULL);
  lt = localtime(&tv.tv_sec);
  if (t == -1 || lt == NULL) {
    printf("CURRENT TIME UNKNOWN ");
    return;
  }
  printf("%02d:%02d:%02d.%06ld", lt->tm_hour, lt->tm_min, lt->tm_sec,
         tv.tv_usec);
  return;
}


x86 assembly (clang, -O0):
<printt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
lea    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     116e <printt+0x3e>
cmpq   $0x0,-0x10(%rbp)
jne    1181 <printt+0x51>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a7 <printt+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%r8d
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printt>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
cmp    $0xffffffff,%ebx
je     1174 <printt+0x44>
test   %rax,%rax
je     1174 <printt+0x44>
mov    (%rax),%esi
mov    0x4(%rax),%edx
mov    0x8(%rax),%ecx
mov    0x8(%rsp),%r8d
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1182 <printt+0x52>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [22 x i8] c"CURRENT TIME UNKNOWN \00"
@.str.1 = [21 x i8] c"%02d:%02d:%02d.%06ld\00"
define void @printt() {
%1 = alloca %struct.timeval
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
store i32 %4, i32* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%6 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %6, %struct.tm** %2
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = load %struct.tm*, %struct.tm** %2
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9, %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %27
14: ; preds = %9
%15 = load %struct.tm*, %struct.tm** %2
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load %struct.tm*, %struct.tm** %2
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load %struct.tm*, %struct.tm** %2
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %20, i32 %23, i32 %25)
br label %27
27: ; preds = %14, %12
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [22 x i8] c"CURRENT TIME UNKNOWN \00"
@.str.1 = [21 x i8] c"%02d:%02d:%02d.%06ld\00"
define void @printt() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%5 = call %struct.tm* @localtime(i32* %4)
%6 = icmp eq i32 %3, -1
%7 = icmp eq %struct.tm* %5, null
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %21
11: ; preds = %0
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15, i32 %17, i32 %19)
br label %21
21: ; preds = %11, %9
ret void
}