#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 /*<<< orphan*/ time_t;
struct tm {
  scalar_t__ tm_yday;
  scalar_t__ tm_hour;
  scalar_t__ tm_min;
  scalar_t__ tm_sec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, scalar_t__);
char *time_format_2(time_t dt) {
  struct tm *delta;
  static char buf[64];
  delta = gmtime((time_t *)&dt);
  if (delta->tm_yday > 0)
    snprintf(buf, sizeof(buf), "%dd", delta->tm_yday);
  else if (delta->tm_hour > 0)
    snprintf(buf, sizeof(buf), "%dh", delta->tm_hour);
  else if (delta->tm_min > 0)
    snprintf(buf, sizeof(buf), "%dm", delta->tm_min);
  else
    snprintf(buf, sizeof(buf), "%ds", delta->tm_sec);
  return buf;
}


x86 assembly (clang, -O0):
<time_format_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jle    116a <time_format_2+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0x2eec(%rip),%rdi
mov    $0x40,%esi
lea    0xea0(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11fc <time_format_2+0xdc>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jle    119e <time_format_2+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0x2eb8(%rip),%rdi
mov    $0x40,%esi
lea    0xe70(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11f7 <time_format_2+0xd7>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jle    11d2 <time_format_2+0xb2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0x2e84(%rip),%rdi
mov    $0x40,%esi
lea    0xe40(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11f2 <time_format_2+0xd2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0x2e5f(%rip),%rdi
mov    $0x40,%esi
lea    0xe1f(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11f7 <time_format_2+0xd7>
jmp    11fc <time_format_2+0xdc>
lea    0x2e3d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_format_2>:
push   %rax
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <gmtime@plt>
mov    (%rax),%rcx
test   %rcx,%rcx
jle    1147 <time_format_2+0x27>
lea    0x2f02(%rip),%rdi
lea    0xebb(%rip),%rdx
jmp    118b <time_format_2+0x6b>
mov    0x8(%rax),%rcx
test   %rcx,%rcx
jle    1160 <time_format_2+0x40>
lea    0x2ee9(%rip),%rdi
lea    0xea6(%rip),%rdx
jmp    118b <time_format_2+0x6b>
mov    0x10(%rax),%rcx
test   %rcx,%rcx
jle    1179 <time_format_2+0x59>
lea    0x2ed0(%rip),%rdi
lea    0xe91(%rip),%rdx
jmp    118b <time_format_2+0x6b>
mov    0x18(%rax),%rcx
lea    0x2ebc(%rip),%rdi
lea    0xe81(%rip),%rdx
mov    $0x40,%esi
call   1030 <snprintf@plt>
lea    0x2ea4(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64, i64 }
@time_format_2.buf = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"%dd\00"
@.str.1 = [4 x i8] c"%dh\00"
@.str.2 = [4 x i8] c"%dm\00"
@.str.3 = [4 x i8] c"%ds\00"
define i8* @time_format_2(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
store i32 %0, i32* %2
%4 = call %struct.tm* @gmtime(i32* %2)
store %struct.tm* %4, %struct.tm** %3
%5 = load %struct.tm*, %struct.tm** %3
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%7 = load i64, i64* %6
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load %struct.tm*, %struct.tm** %3
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %12)
br label %41
14: ; preds = %1
%15 = load %struct.tm*, %struct.tm** %3
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load %struct.tm*, %struct.tm** %3
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 1
%22 = load i64, i64* %21
%23 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %22)
br label %40
24: ; preds = %14
%25 = load %struct.tm*, %struct.tm** %3
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 2
%27 = load i64, i64* %26
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load %struct.tm*, %struct.tm** %3
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 2
%32 = load i64, i64* %31
%33 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %32)
br label %39
34: ; preds = %24
%35 = load %struct.tm*, %struct.tm** %3
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 3
%37 = load i64, i64* %36
%38 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %37)
br label %39
39: ; preds = %34, %29
br label %40
40: ; preds = %39, %19
br label %41
41: ; preds = %40, %9
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64, i64 }
@time_format_2.buf = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"%dd\00"
@.str.1 = [4 x i8] c"%dh\00"
@.str.2 = [4 x i8] c"%dm\00"
@.str.3 = [4 x i8] c"%ds\00"
define i8* @time_format_2(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call %struct.tm* @gmtime(i32* %2)
%4 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%5 = load i64, i64* %4
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %25
9: ; preds = %1
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%11 = load i64, i64* %10
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %25
15: ; preds = %9
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%17 = load i64, i64* %16
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %17)
br label %25
21: ; preds = %15
%22 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%23 = load i64, i64* %22
%24 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %13, %21, %19, %7
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @time_format_2.buf, i64 0, i64 0)
}