#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 {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};
struct tcb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ tprintf(char *, ...);
int umove(struct tcb *, long, struct timespec *);
int /*<<< orphan*/ verbose(struct tcb *);
void print_timespec(struct tcb *tcp, long addr) {
  if (addr == 0)
    tprintf("NULL");
  else if (!verbose(tcp))
    tprintf("%#lx", addr);
  else {
    int rc;
    {
      struct timespec ts;
      if ((rc = umove(tcp, addr, &ts)) >= 0)
        tprintf("{%lu, %lu}", (unsigned long)ts.tv_sec,
                (unsigned long)ts.tv_nsec);
    }
    if (rc < 0)
      tprintf("{...}");
  }
}


x86 assembly (clang, -O0):
<print_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115e <print_timespec+0x2e>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
jmp    11dc <print_timespec+0xac>
mov    -0x8(%rbp),%rdi
call   1050 <verbose@plt>
cmp    $0x0,%eax
jne    1187 <print_timespec+0x57>
mov    -0x10(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
jmp    11d7 <print_timespec+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <umove@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     11ba <print_timespec+0x8a>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jge    11d2 <print_timespec+0xa2>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <tprintf@plt>
jmp    11d7 <print_timespec+0xa7>
jmp    11dc <print_timespec+0xac>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_timespec>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     1179 <print_timespec+0x49>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <verbose@plt>
test   %eax,%eax
je     118e <print_timespec+0x5e>
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <umove@plt>
test   %eax,%eax
js     11a6 <print_timespec+0x76>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1030 <tprintf@plt>
jmp    11b4 <print_timespec+0x84>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <tprintf@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <tprintf@plt>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1030 <tprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tcb = type { i32 }
%struct.timespec = type { i64, i64 }
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"%#lx\00"
@.str.2 = [11 x i8] c"{%lu, %lu}\00"
@.str.3 = [6 x i8] c"{...}\00"
define void @print_timespec(%struct.tcb* %0, i64 %1) {
%3 = alloca %struct.tcb*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.timespec
store %struct.tcb* %0, %struct.tcb** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
11: ; preds = %2
%12 = load %struct.tcb*, %struct.tcb** %3
%13 = call i32 @verbose(%struct.tcb* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i64, i64* %4
%17 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %16)
br label %35
18: ; preds = %11
%19 = load %struct.tcb*, %struct.tcb** %3
%20 = load i64, i64* %4
%21 = call i32 @umove(%struct.tcb* %19, i64 %20, %struct.timespec* %6)
store i32 %21, i32* %5
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%27 = load i64, i64* %26
%28 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %25, i64 %27)
br label %29
29: ; preds = %23, %18
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34, %15
br label %36
36: ; preds = %35, %9
ret void
}

LLVM IR (-O2):
%struct.tcb = type { i32 }
%struct.timespec = type { i64, i64 }
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"%#lx\00"
@.str.2 = [11 x i8] c"{%lu, %lu}\00"
@.str.3 = [6 x i8] c"{...}\00"
define void @print_timespec(%struct.tcb* %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = icmp eq i64 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %24
7: ; preds = %2
%8 = tail call i32 @verbose(%struct.tcb* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %1)
br label %24
12: ; preds = %7
%13 = bitcast %struct.timespec* %3 to i8*
%14 = call i32 @umove(%struct.tcb* %0, i64 %1, %struct.timespec* %3)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%20 = load i64, i64* %19
%21 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %18, i64 %20)
br label %24
22: ; preds = %12
%23 = call i32 (i8*, ...) @tprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %16, %22, %10, %5
ret void
}