#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 pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned long long *);
int snprintf(char *, int, char *, int);
unsigned long long get_process_start_time(pid_t pid) {
  char filename[255];
  int ret = snprintf(filename, 255, "/proc/%d/stat", pid);
  if (ret >= 255)
    return 0;
  FILE *f = fopen(filename, "r");
  if (!f)
    return 0;
  unsigned long long starttime;
  ret = fscanf(f,
               "%*d "
               "%*s "
               "%*c "
               "%*d "
               "%*d "
               "%*d "
               "%*d	"
               "%*d "
               "%*u "
               "%*lu "
               "%*lu "
               "%*lu "
               "%*lu "
               "%*lu "
               "%*lu "
               "%*ld "
               "%*ld "
               "%*ld "
               "%*ld "
               "%*ld "
               "%*ld "
               "%llu ",
               &starttime);
  fclose(f);
  if (ret != 1)
    return 0;
  return starttime;
}


x86 assembly (clang, -O0):
<get_process_start_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0xff,%esi
lea    0xe9c(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xff,-0x114(%rbp)
jl     118c <get_process_start_time+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    1212 <get_process_start_time+0xd2>
lea    -0x110(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    11c1 <get_process_start_time+0x81>
movq   $0x0,-0x8(%rbp)
jmp    1212 <get_process_start_time+0xd2>
mov    -0x120(%rbp),%rdi
lea    0xe41(%rip),%rsi
lea    -0x128(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x114(%rbp)
mov    -0x120(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x114(%rbp)
je     1207 <get_process_start_time+0xc7>
movq   $0x0,-0x8(%rbp)
jmp    1212 <get_process_start_time+0xd2>
mov    -0x128(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_process_start_time>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
mov    %edi,%ecx
lea    0xeae(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
call   1040 <snprintf@plt>
cmp    $0xfe,%eax
jg     11ab <get_process_start_time+0x6b>
lea    0xe9f(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ab <get_process_start_time+0x6b>
mov    %rax,%rbx
lea    0xe88(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    11ab <get_process_start_time+0x6b>
mov    0x8(%rsp),%rax
jmp    11ad <get_process_start_time+0x6d>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [102 x i8] c"%*d %*s %*c %*d %*d %*d %*d\09%*d %*u %*lu %*lu %*lu %*lu %*lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu \00"
define i64 @get_process_start_time(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
store i32 %0, i32* %3
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* %3
%10 = call i32 @snprintf(i8* %8, i32 255, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 255
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 0, i64* %2
br label %30
14: ; preds = %1
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %14
store i64 0, i64* %2
br label %30
20: ; preds = %14
%21 = load i32*, i32** %6
%22 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.2, i64 0, i64 0), i64* %7)
store i32 %22, i32* %5
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %20
store i64 0, i64* %2
br label %30
28: ; preds = %20
%29 = load i64, i64* %7
store i64 %29, i64* %2
br label %30
30: ; preds = %28, %27, %19, %13
%31 = load i64, i64* %2
ret i64 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/%d/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [102 x i8] c"%*d %*s %*c %*d %*d %*d %*d\09%*d %*u %*lu %*lu %*lu %*lu %*lu %*lu %*ld %*ld %*ld %*ld %*ld %*ld %llu \00"
define i64 @get_process_start_time(i32 %0) {
%2 = alloca [255 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 255, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = icmp sgt i32 %5, 254
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = bitcast i64* %3 to i8*
%12 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%13 = call i32 @fclose(i32* %8)
%14 = icmp eq i32 %12, 1
%15 = load i64, i64* %3
%16 = select i1 %14, i64 %15, i64 0
br label %17
17: ; preds = %10, %7, %1
%18 = phi i64 [ 0, %1 ], [ %16, %10 ], [ 0, %7 ]
ret i64 %18
}