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

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, long, ...);
char *makeHumanReadableTime(char *result, long int elapsedSeconds) {
  int seconds = elapsedSeconds;
  int hours = seconds / (60 * 60);
  seconds -= hours * (60 * 60);
  int minutes = seconds / 60;
  seconds -= minutes * 60;
  if (elapsedSeconds >= (60 * 60)) {
    if (seconds == 0) {
      sprintf(result, "%dh%02dm", hours, minutes);
    } else {
      sprintf(result, "%dh%02dm%02ds", hours, minutes, seconds);
    }
  } else if (elapsedSeconds >= 60) {
    if (seconds == 0) {
      sprintf(result, "%dm", minutes);
    } else {
      sprintf(result, "%dm%02ds", minutes, seconds);
    }
  } else {
    sprintf(result, "%lds", elapsedSeconds);
  }
  return result;
}


x86 assembly (clang, -O0):
<makeHumanReadableTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
imul   $0xe10,-0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
imul   $0x3c,-0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0xe10,-0x10(%rbp)
jl     11b6 <makeHumanReadableTime+0xa6>
cmpl   $0x0,-0x14(%rbp)
jne    1194 <makeHumanReadableTime+0x84>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11b1 <makeHumanReadableTime+0xa1>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    121f <makeHumanReadableTime+0x10f>
cmpq   $0x3c,-0x10(%rbp)
jl     1204 <makeHumanReadableTime+0xf4>
cmpl   $0x0,-0x14(%rbp)
jne    11e6 <makeHumanReadableTime+0xd6>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rdx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11ff <makeHumanReadableTime+0xef>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    121a <makeHumanReadableTime+0x10a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    121f <makeHumanReadableTime+0x10f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeHumanReadableTime>:
push   %rbx
mov    %rsi,%rdx
mov    %rdi,%rbx
movslq %edx,%rcx
imul   $0xffffffff91a2b3c5,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%esi
shr    $0x1f,%esi
sar    $0xb,%eax
add    %esi,%eax
imul   $0xfffff1f0,%eax,%esi
add    %ecx,%esi
movslq %esi,%rsi
imul   $0xffffffff88888889,%rsi,%rcx
shr    $0x20,%rcx
add    %esi,%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
sar    $0x5,%ecx
add    %edi,%ecx
imul   $0xffffffc4,%ecx,%r8d
add    %esi,%r8d
cmp    $0xe10,%rdx
jl     117e <makeHumanReadableTime+0x6e>
movslq %eax,%rdx
test   %r8d,%r8d
je     11a4 <makeHumanReadableTime+0x94>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c8 <makeHumanReadableTime+0xb8>
cmp    $0x3c,%rdx
jl     119b <makeHumanReadableTime+0x8b>
movslq %ecx,%rdx
test   %r8d,%r8d
je     11b7 <makeHumanReadableTime+0xa7>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
mov    %r8d,%ecx
jmp    11ae <makeHumanReadableTime+0x9e>
lea    0xe82(%rip),%rsi
jmp    11be <makeHumanReadableTime+0xae>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c8 <makeHumanReadableTime+0xb8>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%dh%02dm\00"
@.str.1 = [14 x i8] c"%dh%02dm%02ds\00"
@.str.2 = [4 x i8] c"%dm\00"
@.str.3 = [9 x i8] c"%dm%02ds\00"
@.str.4 = [5 x i8] c"%lds\00"
define i8* @makeHumanReadableTime(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = sdiv i32 %10, 3600
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = mul nsw i32 %12, 3600
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, %13
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = sdiv i32 %16, 60
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = mul nsw i32 %18, 60
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, %19
store i32 %21, i32* %5
%22 = load i64, i64* %4
%23 = icmp sge i64 %22, 3600
br i1 %23, label %24, label %41
24: ; preds = %2
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = load i32, i32* %7
%32 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %30, i32 %31)
br label %40
33: ; preds = %24
%34 = load i8*, i8** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = load i32, i32* %7
%38 = load i32, i32* %5
%39 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %36, i32 %37, i32 %38)
br label %40
40: ; preds = %33, %27
br label %64
41: ; preds = %2
%42 = load i64, i64* %4
%43 = icmp sge i64 %42, 60
br i1 %43, label %44, label %59
44: ; preds = %41
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i8*, i8** %3
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %50)
br label %58
52: ; preds = %44
%53 = load i8*, i8** %3
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = load i32, i32* %5
%57 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %55, i32 %56)
br label %58
58: ; preds = %52, %47
br label %63
59: ; preds = %41
%60 = load i8*, i8** %3
%61 = load i64, i64* %4
%62 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %61)
br label %63
63: ; preds = %59, %58
br label %64
64: ; preds = %63, %40
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
@.str = [9 x i8] c"%dh%02dm\00"
@.str.1 = [14 x i8] c"%dh%02dm%02ds\00"
@.str.2 = [4 x i8] c"%dm\00"
@.str.3 = [9 x i8] c"%dm%02ds\00"
@.str.4 = [5 x i8] c"%lds\00"
define i8* @makeHumanReadableTime(i8* returned writeonly %0, i64 %1) {
%3 = trunc i64 %1 to i32
%4 = sdiv i32 %3, 3600
%5 = mul nsw i32 %4, -3600
%6 = add i32 %5, %3
%7 = sdiv i32 %6, 60
%8 = mul nsw i32 %7, -60
%9 = add i32 %8, %6
%10 = icmp sgt i64 %1, 3599
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = icmp eq i32 %9, 0
%13 = sext i32 %4 to i64
br i1 %12, label %14, label %16
14: ; preds = %11
%15 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %13, i32 %7)
br label %29
16: ; preds = %11
%17 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %13, i32 %7, i32 %9)
br label %29
18: ; preds = %2
%19 = icmp sgt i64 %1, 59
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = icmp eq i32 %9, 0
%22 = sext i32 %7 to i64
br i1 %21, label %23, label %25
23: ; preds = %20
%24 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %29
25: ; preds = %20
%26 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %22, i32 %9)
br label %29
27: ; preds = %18
%28 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %1)
br label %29
29: ; preds = %27, %25, %23, %14, %16
ret i8* %0
}