#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;
struct tm {
  int tm_hour;
  int tm_min;
  int tm_sec;
  int tm_yday;
};

/* Variables and functions */
int /*<<< orphan*/ gmtime_r(int *, struct tm *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int, int);
const char *frrtime_to_interval(time_t t, char *buf, size_t buflen) {
  struct tm tm;
  gmtime_r(&t, &tm);
  if (t < 60 * 60 * 24)
    snprintf(buf, buflen, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
  else if (t < 60 * 60 * 24 * 7)
    snprintf(buf, buflen, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour, tm.tm_min);
  else
    snprintf(buf, buflen, "%02dw%dd%02dh", tm.tm_yday / 7,
             tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
  return buf;
}


x86 assembly (clang, -O0):
<frrtime_to_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x4(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <gmtime_r@plt>
cmpl   $0x15180,-0x4(%rbp)
jge    1171 <frrtime_to_interval+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xe99(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11e3 <frrtime_to_interval+0xc3>
cmpl   $0x93a80,-0x4(%rbp)
jge    11a2 <frrtime_to_interval+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xe77(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11de <frrtime_to_interval+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x1c(%rbp),%eax
mov    $0x7,%r9d
cltd
idiv   %r9d
imul   $0x7,%eax,%eax
sub    %eax,%r8d
mov    -0x28(%rbp),%r9d
lea    0xe44(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11e3 <frrtime_to_interval+0xc3>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frrtime_to_interval>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <gmtime_r@plt>
mov    0x4(%rsp),%eax
cmp    $0x1517f,%eax
jg     1162 <frrtime_to_interval+0x42>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
lea    0xea0(%rip),%rdx
jmp    117e <frrtime_to_interval+0x5e>
mov    0x14(%rsp),%ecx
cmp    $0x93a7f,%eax
ja     1186 <frrtime_to_interval+0x66>
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
lea    0xe91(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
jmp    11c4 <frrtime_to_interval+0xa4>
movslq %ecx,%rax
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
mov    %eax,%r8d
sub    %edx,%r8d
add    %ecx,%r8d
mov    0x8(%rsp),%r9d
lea    0xe61(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%ecx
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32 }
@.str = [15 x i8] c"%02d:%02d:%02d\00"
@.str.1 = [14 x i8] c"%dd%02dh%02dm\00"
@.str.2 = [14 x i8] c"%02dw%dd%02dh\00"
define i8* @frrtime_to_interval(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.tm
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = call i32 @gmtime_r(i32* %4, %struct.tm* %7)
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 86400
br i1 %10, label %11, label %21
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i8* %12, i64 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17, i32 %19)
br label %51
21: ; preds = %3
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 604800
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @snprintf(i8* %25, i64 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %30, i32 %32)
br label %50
34: ; preds = %21
%35 = load i8*, i8** %5
%36 = load i64, i64* %6
%37 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
%38 = load i32, i32* %37
%39 = sdiv i32 %38, 7
%40 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
%43 = load i32, i32* %42
%44 = sdiv i32 %43, 7
%45 = mul nsw i32 %44, 7
%46 = sub nsw i32 %41, %45
%47 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @snprintf(i8* %35, i64 %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %46, i32 %48)
br label %50
50: ; preds = %34, %24
br label %51
51: ; preds = %50, %11
%52 = load i8*, i8** %5
ret i8* %52
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32 }
@.str = [15 x i8] c"%02d:%02d:%02d\00"
@.str.1 = [14 x i8] c"%dd%02dh%02dm\00"
@.str.2 = [14 x i8] c"%02dw%dd%02dh\00"
define i8* @frrtime_to_interval(i32 %0, i8* returned %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %0, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = call i32 @gmtime_r(i32* %4, %struct.tm* %5)
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 86400
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%16 = load i32, i32* %15
%17 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14, i32 %16)
br label %35
18: ; preds = %3
%19 = icmp ult i32 %8, 604800
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%21 = load i32, i32* %20
br i1 %19, label %22, label %28
22: ; preds = %18
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %24, i32 %26)
br label %35
28: ; preds = %18
%29 = sdiv i32 %21, 7
%30 = mul nsw i32 %29, -7
%31 = add i32 %30, %21
%32 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31, i32 %33)
br label %35
35: ; preds = %22, %28, %10
ret i8* %1
}