#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 unsigned long time_t;
struct tm {
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_min;
  int /*<<< orphan*/ tm_hour;
};

/* Variables and functions */
struct tm *localtime(unsigned long *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long, unsigned long,
                            unsigned long, unsigned long, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ time(unsigned long *);
const char *uptime_from_boottime(time_t boottime) {
  static char buf[64];
  time_t now;
  struct tm *ltime;
  unsigned long diff_secs;
  unsigned long rest;
  unsigned long days, hours, minutes, seconds;
  time(&now);
  ltime = localtime(&now);
  diff_secs = now - boottime;
  days = diff_secs / 86400;
  rest = diff_secs % 86400;
  hours = rest / 3600;
  rest = rest % 3600;
  minutes = rest / 60;
  rest = rest % 60;
  seconds = (unsigned int)rest;
  snprintf(buf, sizeof buf, "up %ld+%02ld:%02ld:%02ld  %02d:%02d:%02d", days,
           hours, minutes, seconds, ltime->tm_hour, ltime->tm_min,
           ltime->tm_sec);
  return buf;
}


x86 assembly (clang, -O0):
<uptime_from_boottime>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <time@plt>
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x15180,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x15180,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%eax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    -0x50(%rbp),%rbx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r11d
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%r10d
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
lea    0x2e4e(%rip),%rdi
mov    $0x40,%esi
lea    0xdf2(%rip),%rdx
mov    %rbx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <snprintf@plt>
lea    0x2e24(%rip),%rax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<uptime_from_boottime>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <time@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    %rax,%rsi
mov    (%rsp),%rdi
sub    %rbx,%rdi
movabs $0xc22e450672894ab7,%rcx
45 2e c2
mov    %rdi,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x10,%rcx
imul   $0x15180,%rcx,%rax
sub    %rax,%rdi
mov    $0x91a2b3c5,%r8d
imul   %rdi,%r8
shr    $0x2b,%r8
imul   $0xe10,%r8d,%eax
sub    %eax,%edi
imul   $0x8889,%edi,%r9d
shr    $0x15,%r9d
imul   $0x3c,%r9d,%eax
sub    %eax,%edi
movzwl %di,%r10d
mov    0x8(%rsi),%r11d
mov    (%rsi),%eax
mov    0x4(%rsi),%ebx
lea    0x2e9f(%rip),%r14
lea    0xe48(%rip),%rdx
mov    %r14,%rdi
mov    $0x40,%esi
push   %rax
push   %rbx
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@uptime_from_boottime.buf = internal global [64 x i8] zeroinitializer
@.str = [41 x i8] c"up %ld+%02ld:%02ld:%02ld %02d:%02d:%02d\00"
define i8* @uptime_from_boottime(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca %struct.tm*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %2
%11 = call i32 @time(i64* %3)
%12 = call %struct.tm* @localtime(i64* %3)
store %struct.tm* %12, %struct.tm** %4
%13 = load i64, i64* %3
%14 = load i64, i64* %2
%15 = sub i64 %13, %14
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = udiv i64 %16, 86400
store i64 %17, i64* %7
%18 = load i64, i64* %5
%19 = urem i64 %18, 86400
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = udiv i64 %20, 3600
store i64 %21, i64* %8
%22 = load i64, i64* %6
%23 = urem i64 %22, 3600
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = udiv i64 %24, 60
store i64 %25, i64* %9
%26 = load i64, i64* %6
%27 = urem i64 %26, 60
store i64 %27, i64* %6
%28 = load i64, i64* %6
%29 = trunc i64 %28 to i32
%30 = zext i32 %29 to i64
store i64 %30, i64* %10
%31 = load i64, i64* %7
%32 = load i64, i64* %8
%33 = load i64, i64* %9
%34 = load i64, i64* %10
%35 = load %struct.tm*, %struct.tm** %4
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 2
%37 = load i32, i32* %36
%38 = load %struct.tm*, %struct.tm** %4
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = load %struct.tm*, %struct.tm** %4
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uptime_from_boottime.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %31, i64 %32, i64 %33, i64 %34, i32 %37, i32 %40, i32 %43)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uptime_from_boottime.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@uptime_from_boottime.buf = internal global [64 x i8] zeroinitializer
@.str = [41 x i8] c"up %ld+%02ld:%02ld:%02ld %02d:%02d:%02d\00"
define i8* @uptime_from_boottime(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i32 @time(i64* %2)
%5 = call %struct.tm* @localtime(i64* %2)
%6 = load i64, i64* %2
%7 = sub i64 %6, %0
%8 = udiv i64 %7, 86400
%9 = urem i64 %7, 86400
%10 = trunc i64 %9 to i32
%11 = udiv i32 %10, 3600
%12 = zext i32 %11 to i64
%13 = urem i32 %10, 3600
%14 = trunc i32 %13 to i16
%15 = udiv i16 %14, 60
%16 = zext i16 %15 to i64
%17 = urem i16 %14, 60
%18 = zext i16 %17 to i64
%19 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uptime_from_boottime.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %8, i64 %12, i64 %16, i64 %18, i32 %20, i32 %22, i32 %24)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @uptime_from_boottime.buf, i64 0, i64 0)
}