#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 time_t;
struct timeval {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ boottime;

/* Variables and functions */
scalar_t__ difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
scalar_t__ sysctlbyname(char *, struct timeval *, size_t *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char const *get_uptime(void) {
  static char ret[255];
  struct timeval boottime;
  size_t len = sizeof(boottime);
  time_t diff;
  time_t days, hours, minutes;
  if (sysctlbyname("kern.boottime", &boottime, &len, NULL, 0))
    return NULL;
  diff = (time_t)difftime(time(NULL), boottime.tv_sec);
  days = diff / (60 * 60 * 24);
  hours = (diff / (60 * 60)) % 24;
  minutes = (diff / 60) % 60;
  snprintf(ret, 255, "%ld days, %ld hours and %ld minutes", days, hours,
           minutes);
  return ret;
}


x86 assembly (clang, -O0):
<get_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x4,-0x18(%rbp)
lea    0xea9(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
cmp    $0x0,%rax
je     1182 <get_uptime+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1200 <get_uptime+0xc0>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
call   1030 <difftime@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0x2e6c(%rip),%rdi
mov    $0xff,%esi
lea    0xe1e(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2e54(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uptime>:
push   %rbx
sub    $0x10,%rsp
movq   $0x4,0x8(%rsp)
lea    0xeab(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
test   %rax,%rax
jne    1226 <get_uptime+0xe6>
xor    %edi,%edi
call   1050 <time@plt>
mov    (%rsp),%esi
mov    %eax,%edi
call   1030 <difftime@plt>
cltq
imul   $0xffffffffc22e4507,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x10,%ecx
add    %edx,%ecx
imul   $0xffffffff91a2b3c5,%rax,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0xb,%edx
add    %esi,%edx
movslq %edx,%r8
imul   $0x2aaaaaab,%r8,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rdx
add    %esi,%edx
shl    $0x3,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%r8d
imul   $0xffffffff88888889,%rax,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x5,%edx
add    %eax,%edx
movslq %edx,%r9
imul   $0xffffffff88888889,%r9,%rax
shr    $0x20,%rax
add    %r9d,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x5,%eax
add    %edx,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%r9d
lea    0x2e3e(%rip),%rbx
lea    0xdf5(%rip),%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@get_uptime.ret = internal global [255 x i8] zeroinitializer
@.str = [14 x i8] c"kern.boottime\00"
@.str.1 = [36 x i8] c"%ld days, %ld hours and %ld minutes\00"
define i8* @get_uptime() {
%1 = alloca i8*
%2 = alloca %struct.timeval
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i64 4, i64* %3
%8 = call i64 @sysctlbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.timeval* %2, i64* %3, i32* null, i32 0)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i8* null, i8** %1
br label %29
11: ; preds = %0
%12 = call i32 @time(i32* null)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @difftime(i32 %12, i32 %14)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sdiv i32 %17, 86400
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = sdiv i32 %19, 3600
%21 = srem i32 %20, 24
store i32 %21, i32* %6
%22 = load i32, i32* %4
%23 = sdiv i32 %22, 60
%24 = srem i32 %23, 60
store i32 %24, i32* %7
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 @snprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_uptime.ret, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
store i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_uptime.ret, i64 0, i64 0), i8** %1
br label %29
29: ; preds = %11, %10
%30 = load i8*, i8** %1
ret i8* %30
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@get_uptime.ret = internal global [255 x i8] zeroinitializer
@.str = [14 x i8] c"kern.boottime\00"
@.str.1 = [36 x i8] c"%ld days, %ld hours and %ld minutes\00"
define i8* @get_uptime() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast i64* %2 to i8*
store i64 4, i64* %2
%5 = call i64 @sysctlbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.timeval* %1, i64* %2, i32* null, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = call i32 @time(i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = call i64 @difftime(i32 %8, i32 %10)
%12 = trunc i64 %11 to i32
%13 = sdiv i32 %12, 86400
%14 = sdiv i32 %12, 3600
%15 = srem i32 %14, 24
%16 = sdiv i32 %12, 60
%17 = srem i32 %16, 60
%18 = call i32 @snprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @get_uptime.ret, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15, i32 %17)
br label %19
19: ; preds = %0, %7
%20 = phi i8* [ getelementptr inbounds ([255 x i8], [255 x i8]* @get_uptime.ret, i64 0, i64 0), %7 ], [ null, %0 ]
ret i8* %20
}