#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);
void turn_second(time_t sec, char *buffer) {
  if (sec < 60) {
    sprintf(buffer, " %lds ", sec);
  } else if (sec < 60 * 60) {
    sprintf(buffer, " %ldm ", sec / 60);
  } else if (sec < 60 * 60 * 24) {
    sprintf(buffer, " %ldh ", sec / 60 / 60);
  } else {
    sprintf(buffer, " %ldd ", sec / 60 / 60 / 24);
  }
}


x86 assembly (clang, -O0):
<turn_second>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3c,-0x4(%rbp)
jge    1141 <turn_second+0x31>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xec9(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11de <turn_second+0xce>
cmpl   $0xe10,-0x4(%rbp)
jge    1170 <turn_second+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xea1(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11d9 <turn_second+0xc9>
cmpl   $0x15180,-0x4(%rbp)
jge    11a7 <turn_second+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe71(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11d4 <turn_second+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe46(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11d9 <turn_second+0xc9>
jmp    11de <turn_second+0xce>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<turn_second>:
mov    %rsi,%rax
mov    %edi,%edx
cmp    $0x3b,%edi
jg     1129 <turn_second+0x19>
lea    0xedf(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
cmp    $0xe0f,%edx
ja     114c <turn_second+0x3c>
movzwl %dx,%ecx
imul   $0x8889,%ecx,%edx
shr    $0x15,%edx
lea    0xec3(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
mov    %edx,%ecx
cmp    $0x1517f,%edx
ja     1172 <turn_second+0x62>
mov    $0x91a2b3c5,%edx
imul   %rcx,%rdx
shr    $0x2b,%rdx
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>
mov    $0xc22e4507,%edx
imul   %rcx,%rdx
shr    $0x30,%rdx
lea    0xe8f(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c" %lds \00"
@.str.1 = [7 x i8] c" %ldm \00"
@.str.2 = [7 x i8] c" %ldh \00"
@.str.3 = [7 x i8] c" %ldd \00"
define void @turn_second(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 60
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = load i32, i32* %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %37
11: ; preds = %2
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 3600
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 60
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %36
19: ; preds = %11
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 86400
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = load i32, i32* %3
%25 = sdiv i32 %24, 60
%26 = sdiv i32 %25, 60
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %35
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load i32, i32* %3
%31 = sdiv i32 %30, 60
%32 = sdiv i32 %31, 60
%33 = sdiv i32 %32, 24
%34 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28, %22
br label %36
36: ; preds = %35, %14
br label %37
37: ; preds = %36, %7
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c" %lds \00"
@.str.1 = [7 x i8] c" %ldm \00"
@.str.2 = [7 x i8] c" %ldh \00"
@.str.3 = [7 x i8] c" %ldd \00"
define void @turn_second(i32 %0, i8* nocapture writeonly %1) {
%3 = icmp slt i32 %0, 60
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %21
6: ; preds = %2
%7 = icmp ult i32 %0, 3600
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = trunc i32 %0 to i16
%10 = udiv i16 %9, 60
%11 = zext i16 %10 to i32
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %21
13: ; preds = %6
%14 = icmp ult i32 %0, 86400
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = udiv i32 %0, 3600
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %21
18: ; preds = %13
%19 = udiv i32 %0, 86400
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %8, %18, %15, %4
ret void
}