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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strftime(char *, int, char *, struct tm *);
void time_show(struct timespec *ts) {
  clock_gettime(CLOCK_REALTIME, ts);
  struct tm *tm = localtime(&ts->tv_sec);
  char buf[64];
  if (strftime(buf, sizeof(buf), "%r", tm) != 0) {
    printf("time %s\n", buf);
  }
}


x86 assembly (clang, -O0):
<time_show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xe81(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%rax
je     119e <time_show+0x5e>
lea    -0x50(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_show>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1040 <clock_gettime@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
lea    0xe98(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
je     118c <time_show+0x4c>
lea    0xe7f(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.tm = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [3 x i8] c"%r\00"
@.str.1 = [9 x i8] c"time %s\0A\00"
define void @time_show(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.tm*
%4 = alloca [64 x i8]
store %struct.timespec* %0, %struct.timespec** %2
%5 = load i32, i32* @CLOCK_REALTIME
%6 = load %struct.timespec*, %struct.timespec** %2
%7 = call i32 @clock_gettime(i32 %5, %struct.timespec* %6)
%8 = load %struct.timespec*, %struct.timespec** %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%10 = call %struct.tm* @localtime(i32* %9)
store %struct.tm* %10, %struct.tm** %3
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%12 = load %struct.tm*, %struct.tm** %3
%13 = call i64 @strftime(i8* %11, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %1
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
%struct.tm = type { i32 }
@CLOCK_REALTIME = global i32 0
@.str = [3 x i8] c"%r\00"
@.str.1 = [9 x i8] c"time %s\0A\00"
define void @time_show(%struct.timespec* %0) {
%2 = alloca [64 x i8]
%3 = load i32, i32* @CLOCK_REALTIME
%4 = tail call i32 @clock_gettime(i32 %3, %struct.timespec* %0)
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%6 = tail call %struct.tm* @localtime(i32* %5)
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%8 = call i64 @strftime(i8* %7, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %12
12: ; preds = %10, %1
ret void
}