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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
char *interval(time_t tval, const char *updown) {
  static char resbuf[32];
  int days, hours, minutes;
  if (tval < 0) {
    (void)snprintf(resbuf, sizeof(resbuf), "%s      ??:??", updown);
    return (resbuf);
  }
  minutes = (tval + (60 - 1)) / 60;
  hours = minutes / 60;
  minutes %= 60;
  days = hours / 24;
  hours %= 24;
  if (days)
    (void)snprintf(resbuf, sizeof(resbuf), "%s %4d+%02d:%02d", updown, days,
                   hours, minutes);
  else
    (void)snprintf(resbuf, sizeof(resbuf), "%s      %2d:%02d", updown, hours,
                   minutes);
  return (resbuf);
}


x86 assembly (clang, -O0):
<interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1157 <interval+0x47>
mov    -0x18(%rbp),%rcx
lea    0x2f0c(%rip),%rdi
mov    $0x20,%esi
lea    0xec0(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2ef2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    120c <interval+0xfc>
mov    -0xc(%rbp),%eax
add    $0x3b,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11db <interval+0xcb>
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x24(%rbp),%eax
lea    0x2e80(%rip),%rdi
mov    $0x20,%esi
lea    0xe42(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1201 <interval+0xf1>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0x2e52(%rip),%rdi
mov    $0x20,%esi
lea    0xe25(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2e38(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interval>:
push   %rax
mov    %rsi,%rcx
test   %edi,%edi
js     117f <interval+0x6f>
lea    0x3b(%rdi),%edx
mov    $0x88888889,%r8d
mov    %rdx,%r9
imul   %r8,%r9
shr    $0x25,%r9
mov    $0x91a2b3c5,%eax
imul   %rdx,%rax
shr    $0x2b,%rax
mov    %r9,%rsi
imul   %r8,%rsi
shr    $0x25,%rsi
imul   $0x3c,%esi,%esi
sub    %esi,%r9d
mov    $0xaaaaaaab,%esi
imul   %rax,%rsi
shr    $0x24,%rsi
shl    $0x3,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%eax
cmp    $0x15145,%edi
jae    119b <interval+0x8b>
lea    0x2ed2(%rip),%rdi
lea    0xeaa(%rip),%rdx
mov    $0x20,%esi
mov    %eax,%r8d
jmp    11c5 <interval+0xb5>
lea    0x2eba(%rip),%rdi
lea    0xe73(%rip),%rdx
mov    $0x20,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11cc <interval+0xbc>
mov    %edx,%edx
mov    $0xc22e4507,%r8d
imul   %rdx,%r8
shr    $0x30,%r8
mov    %r9d,(%rsp)
lea    0x2e8a(%rip),%rdi
lea    0xe51(%rip),%rdx
mov    $0x20,%esi
mov    %eax,%r9d
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2e6d(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@interval.resbuf = internal global [32 x i8] zeroinitializer
@.str = [14 x i8] c"%s ??:??\00"
@.str.1 = [17 x i8] c"%s %4d+%02d:%02d\00"
@.str.2 = [17 x i8] c"%s %2d:%02d\00"
define i8* @interval(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i8** %3
br label %40
14: ; preds = %2
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 59
%17 = sdiv i32 %16, 60
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sdiv i32 %18, 60
store i32 %19, i32* %7
%20 = load i32, i32* %8
%21 = srem i32 %20, 60
store i32 %21, i32* %8
%22 = load i32, i32* %7
%23 = sdiv i32 %22, 24
store i32 %23, i32* %6
%24 = load i32, i32* %7
%25 = srem i32 %24, 24
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %14
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %30, i32 %31, i32 %32)
br label %39
34: ; preds = %14
%35 = load i8*, i8** %5
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 %36, i32 %37)
br label %39
39: ; preds = %34, %28
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i8** %3
br label %40
40: ; preds = %39, %11
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@interval.resbuf = internal global [32 x i8] zeroinitializer
@.str = [14 x i8] c"%s ??:??\00"
@.str.1 = [17 x i8] c"%s %4d+%02d:%02d\00"
@.str.2 = [17 x i8] c"%s %2d:%02d\00"
define i8* @interval(i32 %0, i8* %1) {
%3 = icmp slt i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %18
6: ; preds = %2
%7 = add nuw nsw i32 %0, 59
%8 = udiv i32 %7, 60
%9 = udiv i32 %7, 3600
%10 = urem i32 %8, 60
%11 = urem i32 %9, 24
%12 = icmp ult i32 %0, 86341
br i1 %12, label %16, label %13
13: ; preds = %6
%14 = udiv i32 %7, 86400
%15 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %14, i32 %11, i32 %10)
br label %18
16: ; preds = %6
%17 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %11, i32 %10)
br label %18
18: ; preds = %13, %16, %4
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @interval.resbuf, i64 0, i64 0)
}