#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 */

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, long, long, long, long);
char *print_uptime(long up_secs, char *retval) {
  long days, hours, mins, secs;
  if (retval == NULL) {
    retval = malloc(20 * sizeof(char));
  }
  mins = up_secs / 60;
  hours = mins / 60;
  hours = hours % 24;
  days = up_secs / (60 * 60 * 24);
  mins = (int)up_secs / 60;
  hours = mins / 60;
  hours = hours % 24;
  mins = mins % 60;
  secs = up_secs % 60;
  snprintf(retval, 20, "Up %ldd, %02ld:%02ld:%02ld", days, hours, mins, secs);
  return retval;
}


x86 assembly (clang, -O0):
<print_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <print_uptime+0x29>
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3c,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rax
mov    $0x14,%esi
lea    0xdf5(%rip),%rdx
mov    %rax,(%rsp)
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_uptime>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
jne    113c <print_uptime+0x1c>
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movabs $0x1845c8a0ce512957,%rcx
c8 45 18
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0xd,%rdx
add    %rdx,%rcx
movslq %ebx,%rdx
imul   $0xffffffff88888889,%rdx,%rax
shr    $0x20,%rax
add    %edx,%eax
mov    %eax,%esi
shr    $0x1f,%esi
sar    $0x5,%eax
add    %esi,%eax
imul   $0xffffffff91a2b3c5,%rdx,%rsi
shr    $0x20,%rsi
add    %edx,%esi
mov    %esi,%edx
shr    $0x1f,%edx
sar    $0xb,%esi
add    %edx,%esi
movslq %esi,%rdx
imul   $0x2aaaaaab,%rdx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
shr    $0x22,%rsi
add    %edi,%esi
shl    $0x3,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%edx
movslq %edx,%r8
cltq
imul   $0xffffffff88888889,%rax,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x5,%edx
add    %esi,%edx
imul   $0x3c,%edx,%edx
sub    %edx,%eax
movslq %eax,%r9
movabs $0x8888888888888889,%rdx
88 88 88
mov    %rbx,%rax
imul   %rdx
add    %rbx,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x5,%rdx
add    %rax,%rdx
imul   $0x3c,%rdx,%rax
sub    %rax,%rbx
mov    %rbx,(%rsp)
lea    0xdff(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
call   1030 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Up %ldd, %02ld:%02ld:%02ld\00"
define i8* @print_uptime(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i8* @malloc(i32 20)
store i8* %12, i8** %4
br label %13
13: ; preds = %11, %2
%14 = load i64, i64* %3
%15 = sdiv i64 %14, 60
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = sdiv i64 %16, 60
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = srem i64 %18, 24
store i64 %19, i64* %6
%20 = load i64, i64* %3
%21 = sdiv i64 %20, 86400
store i64 %21, i64* %5
%22 = load i64, i64* %3
%23 = trunc i64 %22 to i32
%24 = sdiv i32 %23, 60
%25 = sext i32 %24 to i64
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = sdiv i64 %26, 60
store i64 %27, i64* %6
%28 = load i64, i64* %6
%29 = srem i64 %28, 24
store i64 %29, i64* %6
%30 = load i64, i64* %7
%31 = srem i64 %30, 60
store i64 %31, i64* %7
%32 = load i64, i64* %3
%33 = srem i64 %32, 60
store i64 %33, i64* %8
%34 = load i8*, i8** %4
%35 = load i64, i64* %5
%36 = load i64, i64* %6
%37 = load i64, i64* %7
%38 = load i64, i64* %8
%39 = call i32 @snprintf(i8* %34, i32 20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %35, i64 %36, i64 %37, i64 %38)
%40 = load i8*, i8** %4
ret i8* %40
}

LLVM IR (-O2):
@.str = [27 x i8] c"Up %ldd, %02ld:%02ld:%02ld\00"
define i8* @print_uptime(i64 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
br label %6
6: ; preds = %4, %2
%7 = phi i8* [ %5, %4 ], [ %1, %2 ]
%8 = sdiv i64 %0, 86400
%9 = trunc i64 %0 to i32
%10 = sdiv i32 %9, 60
%11 = sdiv i32 %9, 3600
%12 = srem i32 %11, 24
%13 = sext i32 %12 to i64
%14 = srem i32 %10, 60
%15 = sext i32 %14 to i64
%16 = srem i64 %0, 60
%17 = tail call i32 @snprintf(i8* %7, i32 20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %8, i64 %13, i64 %15, i64 %16)
ret i8* %7
}