#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;

/* Variables and functions */
scalar_t__ difftime(scalar_t__, scalar_t__);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
char *system_uptime() {
  static time_t start = 0;
  if (!start) {
    start = time(NULL);
  }
  int uptime = (int)difftime(time(NULL), start);
  int h, m, s;
  h = uptime / 3600;
  m = (uptime - (h * 3600)) / 60;
  s = uptime - (h * 3600) - (m * 60);
  char buf[512];
  snprintf(buf, 512, "%02i:%02i:%02i", h, m, s);
  char *str = (char *)malloc(strlen(buf) + 1);
  strcpy(str, buf);
  return str;
}


x86 assembly (clang, -O0):
<system_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
cmpq   $0x0,0x2ee5(%rip)
jne    1189 <system_uptime+0x29>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,0x2ecf(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,%rdi
mov    0x2ebc(%rip),%rsi
call   1050 <difftime@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
imul   $0xe10,-0x8(%rbp),%ecx
sub    %ecx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
imul   $0xe10,-0x8(%rbp),%ecx
sub    %ecx,%eax
imul   $0x3c,-0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    $0x200,%esi
lea    0xe04(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x218(%rbp),%rax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_uptime>:
push   %r14
push   %rbx
sub    $0x208,%rsp
cmpq   $0x0,0x2ee6(%rip)
jne    1182 <system_uptime+0x22>
xor    %edi,%edi
call   1070 <time@plt>
mov    %rax,0x2ed6(%rip)
xor    %edi,%edi
call   1070 <time@plt>
mov    0x2ec8(%rip),%rsi
mov    %rax,%rdi
call   1050 <difftime@plt>
cltq
imul   $0xffffffff91a2b3c5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0xb,%ecx
add    %edx,%ecx
imul   $0xfffff1f0,%ecx,%edx
add    %eax,%edx
movslq %edx,%rax
imul   $0xffffffff88888889,%rax,%r8
shr    $0x20,%r8
add    %eax,%r8d
mov    %r8d,%edx
shr    $0x1f,%edx
sar    $0x5,%r8d
add    %edx,%r8d
imul   $0xffffffc4,%r8d,%r9d
add    %eax,%r9d
lea    0xe1b(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@system_uptime.start = internal global i64 0
@.str = [15 x i8] c"%02i:%02i:%02i\00"
define i8* @system_uptime() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca i8*
%7 = load i64, i64* @system_uptime.start
%8 = icmp ne i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i64 @time(i32* null)
store i64 %10, i64* @system_uptime.start
br label %11
11: ; preds = %9, %0
%12 = call i64 @time(i32* null)
%13 = load i64, i64* @system_uptime.start
%14 = call i64 @difftime(i64 %12, i64 %13)
%15 = trunc i64 %14 to i32
store i32 %15, i32* %1
%16 = load i32, i32* %1
%17 = sdiv i32 %16, 3600
store i32 %17, i32* %2
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = mul nsw i32 %19, 3600
%21 = sub nsw i32 %18, %20
%22 = sdiv i32 %21, 60
store i32 %22, i32* %3
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, 3600
%26 = sub nsw i32 %23, %25
%27 = load i32, i32* %3
%28 = mul nsw i32 %27, 60
%29 = sub nsw i32 %26, %28
store i32 %29, i32* %4
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 @snprintf(i8* %30, i32 512, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32, i32 %33)
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%36 = call i64 @strlen(i8* %35)
%37 = add nsw i64 %36, 1
%38 = call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %6
%40 = load i8*, i8** %6
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = load i8*, i8** %6
ret i8* %43
}

LLVM IR (-O2):
@system_uptime.start = internal unnamed_addr global i64 0
@.str = [15 x i8] c"%02i:%02i:%02i\00"
define i8* @system_uptime() {
%1 = alloca [512 x i8]
%2 = load i64, i64* @system_uptime.start
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i64 @time(i32* null)
store i64 %5, i64* @system_uptime.start
br label %6
6: ; preds = %4, %0
%7 = tail call i64 @time(i32* null)
%8 = load i64, i64* @system_uptime.start
%9 = tail call i64 @difftime(i64 %7, i64 %8)
%10 = trunc i64 %9 to i32
%11 = sdiv i32 %10, 3600
%12 = mul nsw i32 %11, -3600
%13 = add i32 %12, %10
%14 = sdiv i32 %13, 60
%15 = mul nsw i32 %14, -60
%16 = add i32 %15, %13
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%18 = call i32 @snprintf(i8* %17, i32 512, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14, i32 %16)
%19 = call i64 @strlen(i8* %17)
%20 = add nsw i64 %19, 1
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @strcpy(i8* %22, i8* %17)
ret i8* %22
}