#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;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
const char *apm_time(time_t t) {
  static char buffer[128];
  unsigned long s, m, h, d;
  d = t / (60 * 60 * 24);
  t -= d * (60 * 60 * 24);
  h = t / (60 * 60);
  t -= h * (60 * 60);
  m = t / (60);
  t -= m * (60);
  s = t;
  if (d)
    sprintf(buffer, "%lu day%s, %02lu:%02lu:%02lu", d, d > 1 ? "s" : "", h, m,
            s);
  else
    sprintf(buffer, "%02lu:%02lu:%02lu", h, m, s);
  if (t == -1)
    sprintf(buffer, "unknown");
  return buffer;
}


x86 assembly (clang, -O0):
<apm_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x28(%rbp)
imul   $0x15180,-0x28(%rbp),%rcx
movslq -0x4(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x20(%rbp)
imul   $0xe10,-0x20(%rbp),%rcx
movslq -0x4(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x18(%rbp)
imul   $0x3c,-0x18(%rbp),%rcx
movslq -0x4(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
movslq -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11dc <apm_time+0xcc>
mov    -0x28(%rbp),%rdx
mov    -0x28(%rbp),%rsi
lea    0xe83(%rip),%rcx
lea    0xe73(%rip),%rax
cmp    $0x1,%rsi
cmova  %rax,%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x10(%rbp),%rax
lea    0x2e7b(%rip),%rdi
lea    0xe34(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11fd <apm_time+0xed>
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2e51(%rip),%rdi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
cmpl   $0xffffffff,-0x4(%rbp)
jne    121c <apm_time+0x10c>
lea    0x2e32(%rip),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2e1d(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apm_time>:
push   %rbx
sub    $0x10,%rsp
movslq %edi,%rdx
imul   $0xffffffffc22e4507,%rdx,%rcx
shr    $0x20,%rcx
add    %edx,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x10,%ecx
add    %eax,%ecx
imul   $0xfffeae80,%ecx,%eax
add    %edx,%eax
movslq %eax,%rsi
imul   $0xffffffff91a2b3c5,%rsi,%rax
shr    $0x20,%rax
add    %esi,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0xb,%eax
add    %edi,%eax
cltq
imul   $0xfffff1f0,%eax,%edi
add    %esi,%edi
movslq %edi,%rsi
imul   $0xffffffff88888889,%rsi,%rdi
shr    $0x20,%rdi
add    %esi,%edi
mov    %edi,%ebx
shr    $0x1f,%ebx
sar    $0x5,%edi
add    %ebx,%edi
movslq %edi,%r9
imul   $0xffffffc4,%r9d,%ebx
add    %esi,%ebx
movslq %ebx,%r8
add    $0x1517f,%edx
cmp    $0x2a2ff,%edx
jae    11b1 <apm_time+0xa1>
lea    0x2eaa(%rip),%rdi
lea    0xe6e(%rip),%rsi
mov    %rax,%rdx
mov    %r9,%rcx
xor    %eax,%eax
call   1030 <sprintf@plt>
cmp    $0xffffffff,%ebx
jne    11fb <apm_time+0xeb>
jmp    11ea <apm_time+0xda>
movslq %ecx,%rdx
cmp    $0x2,%ecx
lea    0xe5f(%rip),%rsi
lea    0xe59(%rip),%rcx
cmovae %rsi,%rcx
mov    %r8,(%rsp)
lea    0x2e6c(%rip),%rdi
lea    0xe25(%rip),%rsi
mov    %rax,%r8
xor    %eax,%eax
call   1030 <sprintf@plt>
cmp    $0xffffffff,%ebx
jne    11fb <apm_time+0xeb>
movabs $0x6e776f6e6b6e75,%rax
mov    %rax,0x2e45(%rip)
lea    0x2e3e(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@apm_time.buffer = internal global [128 x i8] zeroinitializer
@.str = [29 x i8] c"%lu day%s, %02lu:%02lu:%02lu\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"%02lu:%02lu:%02lu\00"
@.str.4 = [8 x i8] c"unknown\00"
define i8* @apm_time(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = sdiv i32 %7, 86400
%9 = sext i32 %8 to i64
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = mul i64 %10, 86400
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = sub i64 %13, %11
%15 = trunc i64 %14 to i32
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 3600
%18 = sext i32 %17 to i64
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = mul i64 %19, 3600
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = sub i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 60
%27 = sext i32 %26 to i64
store i64 %27, i64* %4
%28 = load i64, i64* %4
%29 = mul i64 %28, 60
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = sub i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
store i64 %35, i64* %3
%36 = load i64, i64* %6
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %1
%39 = load i64, i64* %6
%40 = load i64, i64* %6
%41 = icmp ugt i64 %40, 1
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%44 = load i64, i64* %5
%45 = load i64, i64* %4
%46 = load i64, i64* %3
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %39, i8* %43, i64 %44, i64 %45, i64 %46)
br label %53
48: ; preds = %1
%49 = load i64, i64* %5
%50 = load i64, i64* %4
%51 = load i64, i64* %3
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %49, i64 %50, i64 %51)
br label %53
53: ; preds = %48, %38
%54 = load i32, i32* %2
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@apm_time.buffer = internal global [128 x i8] zeroinitializer
@.str = [29 x i8] c"%lu day%s, %02lu:%02lu:%02lu\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"%02lu:%02lu:%02lu\00"
define i8* @apm_time(i32 %0) {
%2 = sdiv i32 %0, 86400
%3 = mul nsw i32 %2, -86400
%4 = add i32 %3, %0
%5 = sdiv i32 %4, 3600
%6 = sext i32 %5 to i64
%7 = mul nsw i32 %5, -3600
%8 = add i32 %7, %4
%9 = sdiv i32 %8, 60
%10 = sext i32 %9 to i64
%11 = mul nsw i32 %9, -60
%12 = add i32 %11, %8
%13 = sext i32 %12 to i64
%14 = add i32 %0, 86399
%15 = icmp ult i32 %14, 172799
br i1 %15, label %21, label %16
16: ; preds = %1
%17 = sext i32 %2 to i64
%18 = icmp ugt i32 %2, 1
%19 = select i1 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %17, i8* %19, i64 %6, i64 %10, i64 %13)
br label %23
21: ; preds = %1
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %6, i64 %10, i64 %13)
br label %23
23: ; preds = %21, %16
%24 = icmp eq i32 %12, -1
br i1 %24, label %25, label %26
25: ; preds = %23
store i64 31093567915781749, i64* bitcast ([128 x i8]* @apm_time.buffer to i64*)
br label %26
26: ; preds = %25, %23
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @apm_time.buffer, i64 0, i64 0)
}