#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;
typedef int /*<<< orphan*/ result;

/* Variables and functions */
int snprintf(char *, size_t, char *, int);
const char *sec2str(time_t total) {
  static char result[256];
  int days, hours, mins, secs;
  int first = 1;
  char *p = result;
  char *ep = &result[sizeof(result)];
  int n;
  days = (int)(total / 3600 / 24);
  hours = (int)((total / 3600) % 24);
  mins = (int)((total / 60) % 60);
  secs = (int)(total % 60);
  if (days) {
    first = 0;
    n = snprintf(p, (size_t)(ep - p), "%dd", days);
    if (n < 0 || n >= ep - p)
      return "?";
    p += n;
  }
  if (!first || hours) {
    first = 0;
    n = snprintf(p, (size_t)(ep - p), "%dh", hours);
    if (n < 0 || n >= ep - p)
      return "?";
    p += n;
  }
  if (!first || mins) {
    first = 0;
    n = snprintf(p, (size_t)(ep - p), "%dm", mins);
    if (n < 0 || n >= ep - p)
      return "?";
    p += n;
  }
  snprintf(p, (size_t)(ep - p), "%ds", secs);
  return result;
}


x86 assembly (clang, -O0):
<sec2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x1,-0x20(%rbp)
lea    0x2f17(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0x2f0c(%rip),%rax
add    $0x100,%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1203 <sec2str+0xf3>
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
sub    %rax,%rsi
mov    -0x10(%rbp),%ecx
lea    0xe48(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11e2 <sec2str+0xd2>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jl     11f2 <sec2str+0xe2>
lea    0xe1b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    132a <sec2str+0x21a>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1217 <sec2str+0x107>
cmpl   $0x0,-0x14(%rbp)
je     1282 <sec2str+0x172>
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
sub    %rax,%rsi
mov    -0x14(%rbp),%ecx
lea    0xdcf(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     1261 <sec2str+0x151>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jl     1271 <sec2str+0x161>
lea    0xd9c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    132a <sec2str+0x21a>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1296 <sec2str+0x186>
cmpl   $0x0,-0x18(%rbp)
je     1301 <sec2str+0x1f1>
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
sub    %rax,%rsi
mov    -0x18(%rbp),%ecx
lea    0xd54(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     12e0 <sec2str+0x1d0>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jl     12f0 <sec2str+0x1e0>
lea    0xd1d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    132a <sec2str+0x21a>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
sub    %rax,%rsi
mov    -0x1c(%rbp),%ecx
lea    0xcf4(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2d1a(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sec2str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
movslq %edi,%rax
imul   $0xffffffff91a2b3c5,%rax,%rcx
shr    $0x20,%rcx
add    %edi,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0xb,%ecx
add    %edx,%ecx
movslq %ecx,%r13
imul   $0x2aaaaaab,%r13,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x22,%rcx
add    %edx,%ecx
shl    $0x3,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%r13d
imul   $0xffffffff88888889,%rax,%rbp
shr    $0x20,%rbp
add    %edi,%ebp
mov    %ebp,%ecx
shr    $0x1f,%ecx
sar    $0x5,%ebp
add    %ecx,%ebp
movslq %ebp,%r15
imul   $0xffffffff88888889,%r15,%rcx
shr    $0x20,%rcx
add    %ebp,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x3c,%ecx,%ecx
sub    %ecx,%r15d
lea    0x1517f(%r14),%ecx
cmp    $0x2a2ff,%ecx
jae    11b8 <sec2str+0xa8>
lea    0x2e9b(%rip),%r12
test   %r13d,%r13d
jne    1203 <sec2str+0xf3>
test   %r15d,%r15d
jne    123e <sec2str+0x12e>
jmp    1279 <sec2str+0x169>
imul   $0xffffffffc22e4507,%rax,%rcx
shr    $0x20,%rcx
add    %r14d,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x10,%ecx
add    %eax,%ecx
lea    0x2e69(%rip),%r12
lea    0xe22(%rip),%rdx
mov    $0x100,%esi
mov    %r12,%rdi
call   1030 <snprintf@plt>
cmp    $0xff,%eax
jbe    11fe <sec2str+0xee>
lea    0xe0b(%rip),%r13
jmp    12a5 <sec2str+0x195>
mov    %eax,%eax
add    %rax,%r12
lea    0x2e36(%rip),%rbx
sub    %r12,%rbx
add    $0x100,%rbx
lea    0xdeb(%rip),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13d,%ecx
call   1030 <snprintf@plt>
lea    0xdd4(%rip),%r13
test   %eax,%eax
js     12a5 <sec2str+0x195>
mov    %eax,%eax
cmp    %rax,%rbx
jle    12a5 <sec2str+0x195>
add    %rax,%r12
lea    0x2dfb(%rip),%rbx
sub    %r12,%rbx
add    $0x100,%rbx
lea    0xdb4(%rip),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15d,%ecx
call   1030 <snprintf@plt>
lea    0xd99(%rip),%r13
test   %eax,%eax
js     12a5 <sec2str+0x195>
mov    %eax,%eax
cmp    %rax,%rbx
jle    12a5 <sec2str+0x195>
add    %rax,%r12
imul   $0x3c,%ebp,%eax
sub    %eax,%r14d
lea    0x2dba(%rip),%r13
mov    %r13,%rsi
sub    %r12,%rsi
add    $0x100,%rsi
lea    0xd74(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%ecx
call   1030 <snprintf@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@sec2str.result = internal global [256 x i8] zeroinitializer
@.str = [4 x i8] c"%dd\00"
@.str.1 = [2 x i8] c"?\00"
@.str.2 = [4 x i8] c"%dh\00"
@.str.3 = [4 x i8] c"%dm\00"
@.str.4 = [4 x i8] c"%ds\00"
define i8* @sec2str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %8
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 1, i64 0), i8** %10
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 3600
%14 = sdiv i32 %13, 24
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = sdiv i32 %15, 3600
%17 = srem i32 %16, 24
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 60
%20 = srem i32 %19, 60
store i32 %20, i32* %6
%21 = load i32, i32* %3
%22 = srem i32 %21, 60
store i32 %22, i32* %7
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %51
25: ; preds = %1
store i32 0, i32* %8
%26 = load i8*, i8** %9
%27 = load i8*, i8** %10
%28 = load i8*, i8** %9
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = load i32, i32* %4
%33 = call i32 @snprintf(i8* %26, i64 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = icmp slt i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %25
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = load i8*, i8** %10
%40 = load i8*, i8** %9
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = icmp sge i64 %38, %43
br i1 %44, label %45, label %46
45: ; preds = %36, %25
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %124
46: ; preds = %36
%47 = load i32, i32* %11
%48 = load i8*, i8** %9
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %9
br label %51
51: ; preds = %46, %1
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %5
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %83
57: ; preds = %54, %51
store i32 0, i32* %8
%58 = load i8*, i8** %9
%59 = load i8*, i8** %10
%60 = load i8*, i8** %9
%61 = ptrtoint i8* %59 to i64
%62 = ptrtoint i8* %60 to i64
%63 = sub i64 %61, %62
%64 = load i32, i32* %5
%65 = call i32 @snprintf(i8* %58, i64 %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %64)
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = icmp slt i32 %66, 0
br i1 %67, label %77, label %68
68: ; preds = %57
%69 = load i32, i32* %11
%70 = sext i32 %69 to i64
%71 = load i8*, i8** %10
%72 = load i8*, i8** %9
%73 = ptrtoint i8* %71 to i64
%74 = ptrtoint i8* %72 to i64
%75 = sub i64 %73, %74
%76 = icmp sge i64 %70, %75
br i1 %76, label %77, label %78
77: ; preds = %68, %57
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %124
78: ; preds = %68
%79 = load i32, i32* %11
%80 = load i8*, i8** %9
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds i8, i8* %80, i64 %81
store i8* %82, i8** %9
br label %83
83: ; preds = %78, %54
%84 = load i32, i32* %8
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* %6
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %115
89: ; preds = %86, %83
store i32 0, i32* %8
%90 = load i8*, i8** %9
%91 = load i8*, i8** %10
%92 = load i8*, i8** %9
%93 = ptrtoint i8* %91 to i64
%94 = ptrtoint i8* %92 to i64
%95 = sub i64 %93, %94
%96 = load i32, i32* %6
%97 = call i32 @snprintf(i8* %90, i64 %95, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %96)
store i32 %97, i32* %11
%98 = load i32, i32* %11
%99 = icmp slt i32 %98, 0
br i1 %99, label %109, label %100
100: ; preds = %89
%101 = load i32, i32* %11
%102 = sext i32 %101 to i64
%103 = load i8*, i8** %10
%104 = load i8*, i8** %9
%105 = ptrtoint i8* %103 to i64
%106 = ptrtoint i8* %104 to i64
%107 = sub i64 %105, %106
%108 = icmp sge i64 %102, %107
br i1 %108, label %109, label %110
109: ; preds = %100, %89
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %124
110: ; preds = %100
%111 = load i32, i32* %11
%112 = load i8*, i8** %9
%113 = sext i32 %111 to i64
%114 = getelementptr inbounds i8, i8* %112, i64 %113
store i8* %114, i8** %9
br label %115
115: ; preds = %110, %86
%116 = load i8*, i8** %9
%117 = load i8*, i8** %10
%118 = load i8*, i8** %9
%119 = ptrtoint i8* %117 to i64
%120 = ptrtoint i8* %118 to i64
%121 = sub i64 %119, %120
%122 = load i32, i32* %7
%123 = call i32 @snprintf(i8* %116, i64 %121, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %122)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), i8** %2
br label %124
124: ; preds = %115, %109, %77, %45
%125 = load i8*, i8** %2
ret i8* %125
}

LLVM IR (-O2):
@sec2str.result = internal global [256 x i8] zeroinitializer
@.str = [4 x i8] c"%dd\00"
@.str.1 = [2 x i8] c"?\00"
@.str.2 = [4 x i8] c"%dh\00"
@.str.3 = [4 x i8] c"%dm\00"
@.str.4 = [4 x i8] c"%ds\00"
define i8* @sec2str(i32 %0) {
%2 = sdiv i32 %0, 3600
%3 = srem i32 %2, 24
%4 = sdiv i32 %0, 60
%5 = srem i32 %4, 60
%6 = srem i32 %0, 60
%7 = add i32 %0, 86399
%8 = icmp ult i32 %7, 172799
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = sdiv i32 %0, 86400
%11 = tail call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), i64 256, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp ugt i32 %11, 255
br i1 %12, label %47, label %13
13: ; preds = %9
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 %14
br label %18
16: ; preds = %1
%17 = icmp eq i32 %3, 0
br i1 %17, label %29, label %18
18: ; preds = %13, %16
%19 = phi i8* [ %15, %13 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), %16 ]
%20 = ptrtoint i8* %19 to i64
%21 = sub i64 ptrtoint (i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 1, i64 0) to i64), %20
%22 = tail call i32 @snprintf(i8* %19, i64 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%23 = icmp slt i32 %22, 0
br i1 %23, label %47, label %24
24: ; preds = %18
%25 = zext i32 %22 to i64
%26 = icmp sgt i64 %21, %25
br i1 %26, label %27, label %47
27: ; preds = %24
%28 = getelementptr inbounds i8, i8* %19, i64 %25
br label %31
29: ; preds = %16
%30 = icmp eq i32 %5, 0
br i1 %30, label %42, label %31
31: ; preds = %27, %29
%32 = phi i8* [ %28, %27 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), %29 ]
%33 = ptrtoint i8* %32 to i64
%34 = sub i64 ptrtoint (i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 1, i64 0) to i64), %33
%35 = tail call i32 @snprintf(i8* %32, i64 %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%36 = icmp slt i32 %35, 0
br i1 %36, label %47, label %37
37: ; preds = %31
%38 = zext i32 %35 to i64
%39 = icmp sgt i64 %34, %38
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = getelementptr inbounds i8, i8* %32, i64 %38
br label %42
42: ; preds = %29, %40
%43 = phi i8* [ %41, %40 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), %29 ]
%44 = ptrtoint i8* %43 to i64
%45 = sub i64 ptrtoint (i8* getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 1, i64 0) to i64), %44
%46 = tail call i32 @snprintf(i8* %43, i64 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %6)
br label %47
47: ; preds = %31, %37, %18, %24, %9, %42
%48 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @sec2str.result, i64 0, i64 0), %42 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %24 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %18 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %37 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %31 ]
ret i8* %48
}