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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  struct timespec ts;
  int secwidth = !strcmp(argv[1] ?: "", "-k") ? 5 : 0;
  clock_gettime(CLOCK_MONOTONIC, &ts);
  printf("%*lu.%06lu\n", secwidth, ts.tv_sec, ts.tv_nsec / 1000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1169 <main+0x39>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1179 <main+0x49>
lea    0xe9e(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1179 <main+0x49>
mov    -0x30(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %dl
xor    $0xff,%dl
xor    %eax,%eax
mov    $0x5,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rax
test   %rax,%rax
lea    0xecb(%rip),%rdi
cmovne %rax,%rdi
lea    0xeb2(%rip),%rsi
call   1050 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,4),%ebx
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0xc(%rsp),%edx
movslq 0x8(%rsp),%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x26,%rcx
add    %eax,%ecx
lea    0xe6f(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"-k\00"
@CLOCK_MONOTONIC = global i32 0
@.str.2 = [12 x i8] c"%*lu.%06lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timespec
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
br label %14
13: ; preds = %2
br label %14
14: ; preds = %13, %12
%15 = phi i8* [ %10, %12 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %13 ]
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 5, i32 0
store i32 %20, i32* %7
%21 = load i32, i32* @CLOCK_MONOTONIC
%22 = call i32 @clock_gettime(i32 %21, %struct.timespec* %6)
%23 = load i32, i32* %7
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%27 = load i32, i32* %26
%28 = sdiv i32 %27, 1000
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %25, i32 %28)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"-k\00"
@CLOCK_MONOTONIC = global i32 0
@.str.2 = [12 x i8] c"%*lu.%06lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %6
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 5, i32 0
%12 = load i32, i32* @CLOCK_MONOTONIC
%13 = call i32 @clock_gettime(i32 %12, %struct.timespec* %3)
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = sdiv i32 %17, 1000
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %15, i32 %18)
ret i32 0
}