#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 */
struct timeval {
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ add_field(int *, int, int *, int, char *, size_t, char *);
size_t fmt_named_interval(struct timeval *, size_t, char *, size_t);
size_t fmt_minutes(struct timeval *tv, int leading_zeros, size_t width,
                   char *buf, size_t buf_len) {
  char *p = buf;
  int secs = tv->tv_sec;
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (secs > (24 * (60 * 60)))
    return fmt_named_interval(tv, width, buf, buf_len);
  if ((secs > 10 * (60 * 60) && width < 5) || (secs > (60 * 60) && width < 4) ||
      (secs > 10 * 60 && width < 2) || width < 1)
    return fmt_named_interval(tv, width, buf, buf_len);
  p += add_field(&secs, (60 * 60), &leading_zeros, 4, ":", width, p);
  p += add_field(&secs, 60, &leading_zeros, 1, "", width, p);
  return p - buf;
}


x86 assembly (clang, -O0):
<fmt_minutes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    1165 <fmt_minutes+0x45>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jb     1171 <fmt_minutes+0x51>
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x15180,-0x3c(%rbp)
jle    119c <fmt_minutes+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <fmt_named_interval@plt>
mov    %rax,-0x8(%rbp)
jmp    1290 <fmt_minutes+0x170>
cmpl   $0x8ca0,-0x3c(%rbp)
jle    11b4 <fmt_minutes+0x94>
cmpq   $0x5,-0x20(%rbp)
jb     11ef <fmt_minutes+0xcf>
cmpl   $0xe10,-0x3c(%rbp)
jle    11cc <fmt_minutes+0xac>
cmpq   $0x4,-0x20(%rbp)
jb     11ef <fmt_minutes+0xcf>
cmpl   $0x258,-0x3c(%rbp)
jle    11e4 <fmt_minutes+0xc4>
cmpq   $0x2,-0x20(%rbp)
jb     11ef <fmt_minutes+0xcf>
cmpq   $0x1,-0x20(%rbp)
jae    120d <fmt_minutes+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <fmt_named_interval@plt>
mov    %rax,-0x8(%rbp)
jmp    1290 <fmt_minutes+0x170>
mov    -0x20(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    -0x3c(%rbp),%rdi
mov    $0xe10,%esi
lea    -0x14(%rbp),%rdx
mov    $0x4,%ecx
lea    0xdd2(%rip),%r8
mov    %rax,(%rsp)
call   1030 <add_field@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    -0x3c(%rbp),%rdi
mov    $0x3c,%esi
lea    -0x14(%rbp),%rdx
mov    $0x1,%ecx
lea    0xd99(%rip),%r8
mov    %rax,(%rsp)
call   1030 <add_field@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_minutes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %esi,0xc(%rsp)
mov    (%rdi),%eax
mov    %eax,0x8(%rsp)
lea    -0x1(%r8),%rcx
cmp    %r8,%rdx
mov    %rcx,%rbx
cmovb  %rdx,%rbx
test   %rdx,%rdx
cmove  %rcx,%rbx
cmp    $0x15181,%eax
jge    1200 <fmt_minutes+0xe0>
cmp    $0x4,%rbx
ja     116b <fmt_minutes+0x4b>
cmp    $0x8ca0,%eax
jg     1200 <fmt_minutes+0xe0>
cmp    $0x3,%rbx
ja     117c <fmt_minutes+0x5c>
cmp    $0xe10,%eax
jg     1200 <fmt_minutes+0xe0>
cmp    $0x259,%eax
setge  %al
cmp    $0x2,%rbx
setb   %cl
test   %rbx,%rbx
je     1200 <fmt_minutes+0xe0>
and    %al,%cl
jne    1200 <fmt_minutes+0xe0>
mov    %r14,(%rsp)
lea    0xe61(%rip),%r8
lea    0x8(%rsp),%r15
lea    0xc(%rsp),%r12
mov    %r15,%rdi
mov    $0xe10,%esi
mov    %r12,%rdx
mov    $0x4,%ecx
mov    %rbx,%r9
call   1030 <add_field@plt>
movslq %eax,%r13
add    %r14,%r13
mov    %r13,(%rsp)
lea    0xe2f(%rip),%r8
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %r12,%rdx
mov    $0x1,%ecx
mov    %rbx,%r9
call   1030 <add_field@plt>
cltq
add    %r13,%rax
sub    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r8,%rcx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fmt_named_interval@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [2 x i8] c":\00"
@.str.1 = [1 x i8] zeroinitializer
define i64 @fmt_minutes(%struct.timeval* %0, i32 %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i64
%7 = alloca %struct.timeval*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
store %struct.timeval* %0, %struct.timeval** %7
store i32 %1, i32* %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%14 = load i8*, i8** %10
store i8* %14, i8** %12
%15 = load %struct.timeval*, %struct.timeval** %7
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %13
%18 = load i64, i64* %9
%19 = icmp ule i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %5
%21 = load i64, i64* %9
%22 = load i64, i64* %11
%23 = icmp uge i64 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20, %5
%25 = load i64, i64* %11
%26 = sub i64 %25, 1
store i64 %26, i64* %9
br label %27
27: ; preds = %24, %20
%28 = load i32, i32* %13
%29 = icmp sgt i32 %28, 86400
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load %struct.timeval*, %struct.timeval** %7
%32 = load i64, i64* %9
%33 = load i8*, i8** %10
%34 = load i64, i64* %11
%35 = call i64 @fmt_named_interval(%struct.timeval* %31, i64 %32, i8* %33, i64 %34)
store i64 %35, i64* %6
br label %81
36: ; preds = %27
%37 = load i32, i32* %13
%38 = icmp sgt i32 %37, 36000
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i64, i64* %9
%41 = icmp ult i64 %40, 5
br i1 %41, label %57, label %42
42: ; preds = %39, %36
%43 = load i32, i32* %13
%44 = icmp sgt i32 %43, 3600
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i64, i64* %9
%47 = icmp ult i64 %46, 4
br i1 %47, label %57, label %48
48: ; preds = %45, %42
%49 = load i32, i32* %13
%50 = icmp sgt i32 %49, 600
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i64, i64* %9
%53 = icmp ult i64 %52, 2
br i1 %53, label %57, label %54
54: ; preds = %51, %48
%55 = load i64, i64* %9
%56 = icmp ult i64 %55, 1
br i1 %56, label %57, label %63
57: ; preds = %54, %51, %45, %39
%58 = load %struct.timeval*, %struct.timeval** %7
%59 = load i64, i64* %9
%60 = load i8*, i8** %10
%61 = load i64, i64* %11
%62 = call i64 @fmt_named_interval(%struct.timeval* %58, i64 %59, i8* %60, i64 %61)
store i64 %62, i64* %6
br label %81
63: ; preds = %54
%64 = load i64, i64* %9
%65 = load i8*, i8** %12
%66 = call i32 @add_field(i32* %13, i32 3600, i32* %8, i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %64, i8* %65)
%67 = load i8*, i8** %12
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8* %69, i8** %12
%70 = load i64, i64* %9
%71 = load i8*, i8** %12
%72 = call i32 @add_field(i32* %13, i32 60, i32* %8, i32 1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i64 %70, i8* %71)
%73 = load i8*, i8** %12
%74 = sext i32 %72 to i64
%75 = getelementptr inbounds i8, i8* %73, i64 %74
store i8* %75, i8** %12
%76 = load i8*, i8** %12
%77 = load i8*, i8** %10
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
store i64 %80, i64* %6
br label %81
81: ; preds = %63, %57, %30
%82 = load i64, i64* %6
ret i64 %82
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [2 x i8] c":\00"
@.str.1 = [1 x i8] zeroinitializer
define i64 @fmt_minutes(%struct.timeval* %0, i32 %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
store i32 %1, i32* %6
%8 = bitcast i32* %7 to i8*
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = icmp ne i64 %2, 0
%12 = icmp ult i64 %2, %4
%13 = and i1 %11, %12
%14 = add i64 %4, -1
%15 = select i1 %13, i64 %2, i64 %14
%16 = icmp sgt i32 %10, 86400
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = tail call i64 @fmt_named_interval(%struct.timeval* %0, i64 %15, i8* %3, i64 %4)
br label %45
19: ; preds = %5
%20 = icmp sgt i32 %10, 36000
%21 = icmp ult i64 %15, 5
%22 = and i1 %21, %20
br i1 %22, label %33, label %23
23: ; preds = %19
%24 = icmp sgt i32 %10, 3600
%25 = icmp ult i64 %15, 4
%26 = and i1 %25, %24
br i1 %26, label %33, label %27
27: ; preds = %23
%28 = icmp sgt i32 %10, 600
%29 = icmp ult i64 %15, 2
%30 = and i1 %29, %28
%31 = icmp eq i64 %15, 0
%32 = or i1 %31, %30
br i1 %32, label %33, label %35
33: ; preds = %27, %23, %19
%34 = tail call i64 @fmt_named_interval(%struct.timeval* %0, i64 %15, i8* %3, i64 %4)
br label %45
35: ; preds = %27
%36 = call i32 @add_field(i32* %7, i32 3600, i32* %6, i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %15, i8* %3)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %3, i64 %37
%39 = call i32 @add_field(i32* %7, i32 60, i32* %6, i32 1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i64 %15, i8* %38)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = ptrtoint i8* %41 to i64
%43 = ptrtoint i8* %3 to i64
%44 = sub i64 %42, %43
br label %45
45: ; preds = %35, %33, %17
%46 = phi i64 [ %18, %17 ], [ %34, %33 ], [ %44, %35 ]
ret i64 %46
}