#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 *, int, int);
char *strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *duration_min_str(time_t time, char *buf, int len) {
  int hh, mm;
  static char b[64];
  mm = time % 60;
  time /= 60;
  hh = time;
  sprintf(b, "%d:%02d", hh, mm);
  if (!buf)
    return b;
  if (len <= 0)
    return strcpy(buf, b);
  strncpy(buf, b, len);
  buf[len - 1] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<duration_min_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0x2edf(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1050 <sprintf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1198 <duration_min_str+0x68>
lea    0x2ec1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e7 <duration_min_str+0xb7>
cmpl   $0x0,-0x1c(%rbp)
jg     11bb <duration_min_str+0x8b>
mov    -0x18(%rbp),%rdi
lea    0x2ea3(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11e7 <duration_min_str+0xb7>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0x2e87(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duration_min_str>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
movslq %edi,%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x5,%edx
add    %eax,%edx
imul   $0x3c,%edx,%eax
sub    %eax,%ecx
lea    0x2eef(%rip),%rbx
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
test   %r15,%r15
je     119f <duration_min_str+0x6f>
lea    0x2ed4(%rip),%rsi
mov    %r15,%rdi
test   %r14d,%r14d
jle    1197 <duration_min_str+0x67>
mov    %r14d,%edx
call   1030 <strncpy@plt>
add    $0xffffffff,%r14d
movb   $0x0,(%r15,%r14,1)
jmp    119c <duration_min_str+0x6c>
call   1040 <strcpy@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@duration_min_str.b = internal global [64 x i8] zeroinitializer
@.str = [8 x i8] c"%d:%02d\00"
define i8* @duration_min_str(i32 %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = srem i32 %10, 60
store i32 %11, i32* %9
%12 = load i32, i32* %5
%13 = sdiv i32 %12, 60
store i32 %13, i32* %5
%14 = load i32, i32* %5
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %3
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0), i8** %4
br label %37
21: ; preds = %3
%22 = load i32, i32* %7
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = call i8* @strcpy(i8* %25, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0))
store i8* %26, i8** %4
br label %37
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = call i32 @strncpy(i8* %28, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %6
store i8* %36, i8** %4
br label %37
37: ; preds = %27, %24, %20
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
@duration_min_str.b = internal global [64 x i8] zeroinitializer
@.str = [8 x i8] c"%d:%02d\00"
define i8* @duration_min_str(i32 %0, i8* %1, i32 %2) {
%4 = srem i32 %0, 60
%5 = sdiv i32 %0, 60
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %4)
%7 = icmp eq i8* %1, null
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = icmp slt i32 %2, 1
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i8* @strcpy(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0))
br label %17
12: ; preds = %8
%13 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0), i32 %2)
%14 = add nsw i32 %2, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %3, %12, %10
%18 = phi i8* [ %1, %10 ], [ %1, %12 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @duration_min_str.b, i64 0, i64 0), %3 ]
ret i8* %18
}