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

/* Variables and functions */
struct tm *gmtime(scalar_t__ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, ...);
scalar_t__ time(int /*<<< orphan*/ *);
char *uptime(time_t start) {
  static char buf[1024];
  time_t uptime;
  struct tm *tm;
  uptime = time(NULL) - start;
  tm = gmtime(&uptime);
  if (tm->tm_yday)
    snprintf(buf, 1024, "%d days, %02d:%02d:%02d", tm->tm_yday, tm->tm_hour,
             tm->tm_min, tm->tm_sec);
  else
    snprintf(buf, 1024, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
  return buf;
}


x86 assembly (clang, -O0):
<uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
sub    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     11a6 <uptime+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
lea    0x2ec5(%rip),%rdi
mov    $0x400,%esi
lea    0xe69(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11d7 <uptime+0xa7>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
lea    0x2e8c(%rip),%rdi
mov    $0x400,%esi
lea    0xe39(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2e72(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uptime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
sub    %rbx,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <gmtime@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%eax
test   %ecx,%ecx
je     117a <uptime+0x4a>
mov    %eax,(%rsp)
lea    0x2ee4(%rip),%rdi
lea    0xe8d(%rip),%rdx
mov    $0x400,%esi
jmp    1196 <uptime+0x66>
lea    0x2ecf(%rip),%rdi
lea    0xe81(%rip),%rdx
mov    $0x400,%esi
mov    %r8d,%ecx
mov    %r9d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2eac(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32 }
@uptime.buf = internal global [1024 x i8] zeroinitializer
@.str = [24 x i8] c"%d days, %02d:%02d:%02d\00"
@.str.1 = [15 x i8] c"%02d:%02d:%02d\00"
define i8* @uptime(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i64 @time(i32* null)
%5 = sub nsw i64 %4, %0
store i64 %5, i64* %2
%6 = call %struct.tm* @gmtime(i64* %2)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
%10 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%15 = load i32, i32* %14
br i1 %9, label %18, label %16
16: ; preds = %1
%17 = call i32 (i8*, i32, i8*, i32, i32, i32, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @uptime.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %13, i32 %15)
br label %20
18: ; preds = %1
%19 = call i32 (i8*, i32, i8*, i32, i32, i32, ...) @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @uptime.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %13, i32 %15)
br label %20
20: ; preds = %18, %16
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @uptime.buf, i64 0, i64 0)
}