#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;
struct tm {
  int dummy;
};
struct sysinfo {
  int uptime;
};

/* Variables and functions */
int /*<<< orphan*/ *localtime_r(int *, struct tm *);
char *strdup(char *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int sysinfo(struct sysinfo *);
int time(int /*<<< orphan*/ *);
char *myuptime_get_start_date() {
  int str_len = 20;
  char str[str_len];
  time_t now_raw;
  time_t start_raw;
  struct tm start_lt;
  struct sysinfo si;
  if (sysinfo(&si) == -1)
    return NULL;
  now_raw = time(NULL);
  if (now_raw == -1)
    return NULL;
  start_raw = now_raw - si.uptime;
  if (localtime_r(&start_raw, &start_lt) == NULL)
    return NULL;
  if (strftime(str, str_len, "%F %T", &start_lt) < 0)
    return NULL;
  return strdup(str);
}


x86 assembly (clang, -O0):
<myuptime_get_start_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x14,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <sysinfo@plt>
cmp    $0xffffffff,%eax
jne    11ab <myuptime_get_start_date+0x5b>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1252 <myuptime_get_start_date+0x102>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11d5 <myuptime_get_start_date+0x85>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1252 <myuptime_get_start_date+0x102>
mov    -0x24(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    1209 <myuptime_get_start_date+0xb9>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1252 <myuptime_get_start_date+0x102>
mov    -0x48(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xde9(%rip),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <strftime@plt>
cmp    $0x0,%rax
jge    123e <myuptime_get_start_date+0xee>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1252 <myuptime_get_start_date+0x102>
mov    -0x48(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myuptime_get_start_date>:
push   %rbx
sub    $0x30,%rsp
mov    %rsp,%rdi
call   1060 <sysinfo@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     11bc <myuptime_get_start_date+0x6c>
xor    %edi,%edi
call   1040 <time@plt>
cmp    $0xffffffff,%eax
je     11bc <myuptime_get_start_date+0x6c>
sub    (%rsp),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11ba <myuptime_get_start_date+0x6a>
lea    0xe6e(%rip),%rdx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x14,%esi
call   1050 <strftime@plt>
test   %rax,%rax
js     11ba <myuptime_get_start_date+0x6a>
lea    0x10(%rsp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
jmp    11bc <myuptime_get_start_date+0x6c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.sysinfo = type { i32 }
@.str = [6 x i8] c"%F %T\00"
define i8* @myuptime_get_start_date() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca %struct.sysinfo
%9 = alloca i32
store i32 20, i32* %2
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 %11
store i64 %11, i64* %4
%14 = call i32 @sysinfo(%struct.sysinfo* %8)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %0
store i8* null, i8** %1
store i32 1, i32* %9
br label %37
17: ; preds = %0
%18 = call i32 @time(i32* null)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %17
store i8* null, i8** %1
store i32 1, i32* %9
br label %37
22: ; preds = %17
%23 = load i32, i32* %5
%24 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %8, i32 0, i32 0
%25 = load i32, i32* %24
%26 = sub nsw i32 %23, %25
store i32 %26, i32* %6
%27 = call i32* @localtime_r(i32* %6, %struct.tm* %7)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %22
store i8* null, i8** %1
store i32 1, i32* %9
br label %37
30: ; preds = %22
%31 = load i32, i32* %2
%32 = call i64 @strftime(i8* %13, i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i8* null, i8** %1
store i32 1, i32* %9
br label %37
35: ; preds = %30
%36 = call i8* @strdup(i8* %13)
store i8* %36, i8** %1
store i32 1, i32* %9
br label %37
37: ; preds = %35, %34, %29, %21, %16
%38 = load i8*, i8** %3
%39 = load i8*, i8** %1
ret i8* %39
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.sysinfo = type { i32 }
@.str = [6 x i8] c"%F %T\00"
define noalias i8* @myuptime_get_start_date() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = alloca %struct.sysinfo
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = bitcast i32* %1 to i8*
%7 = bitcast %struct.tm* %2 to i8*
%8 = bitcast %struct.sysinfo* %3 to i8*
%9 = call i32 @sysinfo(%struct.sysinfo* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %25, label %11
11: ; preds = %0
%12 = call i32 @time(i32* null)
%13 = icmp eq i32 %12, -1
br i1 %13, label %25, label %14
14: ; preds = %11
%15 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = sub nsw i32 %12, %16
store i32 %17, i32* %1
%18 = call i32* @localtime_r(i32* %1, %struct.tm* %2)
%19 = icmp eq i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %14
%21 = call i64 @strftime(i8* %5, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%22 = icmp slt i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i8* @strdup(i8* %5)
br label %25
25: ; preds = %20, %14, %11, %0, %23
%26 = phi i8* [ %24, %23 ], [ null, %0 ], [ null, %11 ], [ null, %14 ], [ null, %20 ]
ret i8* %26
}