#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 sysinfo {
  int uptime;
};

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
scalar_t__ sysinfo(struct sysinfo *);
char *rpi_sys_uptime() {
  static char data[256];
  int days = 0;
  int hours = 0;
  int mins = 0;
  struct sysinfo sys_info;
  if (sysinfo(&sys_info) != 0) {
    perror("sysinfo");
  }
  days = sys_info.uptime / 86400;
  hours = (sys_info.uptime / 3600) - (days * 24);
  mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
  sprintf(data, "%d days %02d hours %02d minutes %02ld seconds", days, hours,
          mins, sys_info.uptime % 60);
  return data;
}


x86 assembly (clang, -O0):
<rpi_sys_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <sysinfo@plt>
cmp    $0x0,%rax
je     116c <rpi_sys_uptime+0x3c>
lea    0xe99(%rip),%rdi
call   1030 <perror@plt>
mov    -0x10(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
imul   $0x18,-0x4(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
imul   $0x5a0,-0x4(%rbp),%ecx
sub    %ecx,%eax
imul   $0x3c,-0x8(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %edx,%r9d
mov    -0x14(%rbp),%edx
lea    0x2e80(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2e6d(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpi_sys_uptime>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1040 <sysinfo@plt>
test   %rax,%rax
jne    11d5 <rpi_sys_uptime+0xa5>
movslq 0x8(%rsp),%r9
imul   $0xffffffffc22e4507,%r9,%rdx
shr    $0x20,%rdx
add    %r9d,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x10,%edx
add    %eax,%edx
imul   $0xffffffff91a2b3c5,%r9,%rcx
shr    $0x20,%rcx
add    %r9d,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0xb,%ecx
add    %eax,%ecx
lea    0x0(,%rdx,8),%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ecx
imul   $0xfffffa60,%edx,%eax
imul   $0xffffffff88888889,%r9,%rsi
shr    $0x20,%rsi
add    %r9d,%esi
mov    %esi,%edi
shr    $0x1f,%edi
sar    $0x5,%esi
add    %edi,%esi
add    %esi,%eax
imul   $0xffffffc4,%ecx,%r8d
add    %eax,%r8d
imul   $0x3c,%esi,%eax
sub    %eax,%r9d
lea    0x2e93(%rip),%rbx
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe24(%rip),%rdi
call   1030 <perror@plt>
jmp    1148 <rpi_sys_uptime+0x18>

LLVM IR (-O0):
%struct.sysinfo = type { i32 }
@rpi_sys_uptime.data = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"sysinfo\00"
@.str.1 = [46 x i8] c"%d days %02d hours %02d minutes %02ld seconds\00"
define i8* @rpi_sys_uptime() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sysinfo
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%5 = call i64 @sysinfo(%struct.sysinfo* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 86400
store i32 %12, i32* %1
%13 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 3600
%16 = load i32, i32* %1
%17 = mul nsw i32 %16, 24
%18 = sub nsw i32 %15, %17
store i32 %18, i32* %2
%19 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 60
%22 = load i32, i32* %1
%23 = mul nsw i32 %22, 1440
%24 = sub nsw i32 %21, %23
%25 = load i32, i32* %2
%26 = mul nsw i32 %25, 60
%27 = sub nsw i32 %24, %26
store i32 %27, i32* %3
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %4, i32 0, i32 0
%32 = load i32, i32* %31
%33 = srem i32 %32, 60
%34 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @rpi_sys_uptime.data, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29, i32 %30, i32 %33)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @rpi_sys_uptime.data, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.sysinfo = type { i32 }
@rpi_sys_uptime.data = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"sysinfo\00"
@.str.1 = [46 x i8] c"%d days %02d hours %02d minutes %02ld seconds\00"
define i8* @rpi_sys_uptime() {
%1 = alloca %struct.sysinfo
%2 = bitcast %struct.sysinfo* %1 to i8*
%3 = call i64 @sysinfo(%struct.sysinfo* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 86400
%11 = sdiv i32 %9, 3600
%12 = mul nsw i32 %10, -24
%13 = add nsw i32 %12, %11
%14 = sdiv i32 %9, 60
%15 = mul nsw i32 %10, -1440
%16 = add nsw i32 %15, %14
%17 = mul nsw i32 %13, -60
%18 = add nsw i32 %16, %17
%19 = srem i32 %9, 60
%20 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @rpi_sys_uptime.data, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13, i32 %18, i32 %19)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @rpi_sys_uptime.data, i64 0, i64 0)
}