#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*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ ksft_test_result_error(char *);
int sscanf(char *, char *, unsigned long long *);
int read_proc_stat_btime(unsigned long long *boottime_sec) {
  FILE *proc;
  char line_buf[2048];
  proc = fopen("/proc/stat", "r");
  if (proc == NULL) {
    ({
      ksft_test_result_error("Unable to open /proc/stat"
                             ": %m"
                             "\n");
      -1;
    });
    return -1;
  }
  while (fgets(line_buf, 2048, proc)) {
    if (sscanf(line_buf, "btime %llu", boottime_sec) != 1)
      continue;
    fclose(proc);
    return 0;
  }
  if (errno) {
    ({
      ksft_test_result_error("fscanf"
                             ": %m"
                             "\n");
      -1;
    });
    fclose(proc);
    return -errno;
  }
  ({
    ksft_test_result_error("failed to parse /proc/stat"
                           "\n");
    -1;
  });
  fclose(proc);
  return -1;
}


x86 assembly (clang, -O0):
<read_proc_stat_btime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <read_proc_stat_btime+0x53>
lea    0xe85(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x824(%rbp)
ff ff ff
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <read_proc_stat_btime+0x119>
jmp    11a8 <read_proc_stat_btime+0x58>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1201 <read_proc_stat_btime+0xb1>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11ec <read_proc_stat_btime+0x9c>
jmp    11a8 <read_proc_stat_btime+0x58>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1269 <read_proc_stat_btime+0x119>
mov    0x2dd8(%rip),%rax
cmpl   $0x0,(%rax)
je     1243 <read_proc_stat_btime+0xf3>
lea    0xe1f(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x828(%rbp)
ff ff ff
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    0x2da7(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1269 <read_proc_stat_btime+0x119>
lea    0xdf9(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x82c(%rbp)
ff ff ff
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_proc_stat_btime>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r15
lea    0xe98(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c4 <read_proc_stat_btime+0x74>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xea6(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d2 <read_proc_stat_btime+0x82>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1190 <read_proc_stat_btime+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1211 <read_proc_stat_btime+0xc1>
lea    0xe42(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
jmp    120c <read_proc_stat_btime+0xbc>
mov    0x2e07(%rip),%rbx
cmpl   $0x0,(%rbx)
je     11f8 <read_proc_stat_btime+0xa8>
lea    0xe52(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
sub    (%rbx),%eax
jmp    1211 <read_proc_stat_btime+0xc1>
lea    0xe44(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Unable to open /proc/stat: %m\0A\00"
@.str.3 = [11 x i8] c"btime %llu\00"
@errno = global i32 0
@.str.4 = [12 x i8] c"fscanf: %m\0A\00"
@.str.5 = [28 x i8] c"failed to parse /proc/stat\0A\00"
define i32 @read_proc_stat_btime(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32*
%5 = alloca [2048 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i64* %0, i64** %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %6
%14 = load i32, i32* %6
store i32 -1, i32* %2
br label %45
15: ; preds = %1
br label %16
16: ; preds = %26, %15
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i64 @fgets(i8* %17, i32 2048, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%23 = load i64*, i64** %3
%24 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %21
br label %16
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %2
br label %45
30: ; preds = %16
%31 = load i32, i32* @errno
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %7
%35 = load i32, i32* %7
%36 = load i32*, i32** %4
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* @errno
%39 = sub nsw i32 0, %38
store i32 %39, i32* %2
br label %45
40: ; preds = %30
%41 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %8
%42 = load i32, i32* %8
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
store i32 -1, i32* %2
br label %45
45: ; preds = %40, %33, %27, %12
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Unable to open /proc/stat: %m\0A\00"
@.str.3 = [11 x i8] c"btime %llu\00"
@errno = global i32 0
@.str.4 = [12 x i8] c"fscanf: %m\0A\00"
@.str.5 = [28 x i8] c"failed to parse /proc/stat\0A\00"
define i32 @read_proc_stat_btime(i64* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @ksft_test_result_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %27
8: ; preds = %1, %11
%9 = call i64 @fgets(i8* %3, i32 2048, i32* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64* %0)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %8
14: ; preds = %11
%15 = call i32 @fclose(i32* %4)
br label %27
16: ; preds = %8
%17 = load i32, i32* @errno
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @fclose(i32* %4)
%22 = load i32, i32* @errno
%23 = sub nsw i32 0, %22
br label %27
24: ; preds = %16
%25 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @fclose(i32* %4)
br label %27
27: ; preds = %24, %19, %14, %6
%28 = phi i32 [ -1, %6 ], [ 0, %14 ], [ %23, %19 ], [ -1, %24 ]
ret i32 %28
}