#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 uintmax_t;
struct timespec {
  int tv_sec;
};

/* Variables and functions */
int CLOCK_MONOTONIC;
char const *bprintf(char *, int, int);
scalar_t__ clock_gettime(int, struct timespec *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ warn(char *);
const char *uptime(void) {
  char warn_buf[256];
  uintmax_t h, m;
  struct timespec uptime;
  if (clock_gettime(CLOCK_MONOTONIC, &uptime) < 0) {
    snprintf(warn_buf, 256, "clock_gettime %d", CLOCK_MONOTONIC);
    warn(warn_buf);
    return NULL;
  }
  h = uptime.tv_sec / 3600;
  m = uptime.tv_sec % 3600 / 60;
  return bprintf("%juh %jum", h, m);
}


x86 assembly (clang, -O0):
<uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    11a4 <uptime+0x64>
lea    -0x110(%rbp),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%ecx
mov    $0x100,%esi
lea    0xe7a(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f2 <uptime+0xb2>
mov    -0x120(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x114(%rbp)
mov    -0x120(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x118(%rbp)
mov    -0x114(%rbp),%esi
mov    -0x118(%rbp),%edx
lea    0xe28(%rip),%rdi
call   1060 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uptime>:
push   %rbx
sub    $0x110,%rsp
mov    0x2e99(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     11b1 <uptime+0x71>
movslq 0x8(%rsp),%rax
imul   $0xffffffff91a2b3c5,%rax,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
sar    $0xb,%esi
add    %ecx,%esi
imul   $0xe10,%esi,%ecx
sub    %ecx,%eax
movswl %ax,%ecx
imul   $0xffff8889,%ecx,%ecx
shr    $0x10,%ecx
add    %eax,%ecx
movzwl %cx,%eax
movswl %ax,%ecx
shr    $0xf,%eax
sar    $0x5,%ecx
add    %eax,%ecx
movswl %cx,%edx
lea    0xe67(%rip),%rdi
call   1060 <bprintf@plt>
jmp    11d6 <uptime+0x96>
mov    (%rbx),%ecx
lea    0xe46(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <warn@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [17 x i8] c"clock_gettime %d\00"
@.str.1 = [10 x i8] c"%juh %jum\00"
define i8* @uptime() {
%1 = alloca i8*
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = call i64 @clock_gettime(i32 %6, %struct.timespec* %5)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* @CLOCK_MONOTONIC
%12 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = call i32 @warn(i8* %13)
store i8* null, i8** %1
br label %26
15: ; preds = %0
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sdiv i32 %17, 3600
store i32 %18, i32* %3
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%20 = load i32, i32* %19
%21 = srem i32 %20, 3600
%22 = sdiv i32 %21, 60
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i8* @bprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24)
store i8* %25, i8** %1
br label %26
26: ; preds = %15, %9
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [17 x i8] c"clock_gettime %d\00"
@.str.1 = [10 x i8] c"%juh %jum\00"
define i8* @uptime() {
%1 = alloca [256 x i8]
%2 = alloca %struct.timespec
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i64 @clock_gettime(i32 %5, %struct.timespec* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @warn(i8* %3)
br label %21
12: ; preds = %0
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 3600
%16 = srem i32 %14, 3600
%17 = trunc i32 %16 to i16
%18 = sdiv i16 %17, 60
%19 = sext i16 %18 to i32
%20 = call i8* @bprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %19)
br label %21
21: ; preds = %12, %8
%22 = phi i8* [ null, %8 ], [ %20, %12 ]
ret i8* %22
}