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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned long *, unsigned int *,
           unsigned int *);
int /*<<< orphan*/ log_msg(char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void read_loop_counts(unsigned *boots, unsigned *wd_resets, time_t *when) {
  *boots = 0;
  *wd_resets = 0;
  *when = 0;
  FILE *f;
  if ((f = fopen("/var/lib/dsme/boot_count", "r")) == 0) {
    log_msg("Could not open "
            "/var/lib/dsme/boot_count"
            ": %s\n",
            strerror(errno));
  } else {
    if (fscanf(f, "%lu %u %u", (unsigned long *)when, boots, wd_resets) != 3) {
      log_msg("Error reading file "
              "/var/lib/dsme/boot_count");
    }
    (void)fclose(f);
  }
}


x86 assembly (clang, -O0):
<read_loop_counts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
lea    0xec2(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c7 <read_loop_counts+0x77>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <log_msg@plt>
jmp    1203 <read_loop_counts+0xb3>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe51(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x3,%eax
je     11fa <read_loop_counts+0xaa>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <log_msg@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_loop_counts>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
movl   $0x0,(%rdi)
movl   $0x0,(%rsi)
movq   $0x0,(%rdx)
lea    0xed1(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11cd <read_loop_counts+0x7d>
mov    %rax,%rbx
lea    0xe99(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1040 <fscanf@plt>
cmp    $0x3,%eax
je     11ba <read_loop_counts+0x6a>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <log_msg@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe20(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <log_msg@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/var/lib/dsme/boot_count\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [45 x i8] c"Could not open /var/lib/dsme/boot_count: %s\0A\00"
@errno = global i32 0
@.str.3 = [10 x i8] c"%lu %u %u\00"
@.str.4 = [44 x i8] c"Error reading file /var/lib/dsme/boot_count\00"
define void @read_loop_counts(i32* %0, i32* %1, i64* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64* %2, i64** %6
%8 = load i32*, i32** %4
store i32 0, i32* %8
%9 = load i32*, i32** %5
store i32 0, i32* %9
%10 = load i64*, i64** %6
store i64 0, i64* %10
%11 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 (i8*, ...) @log_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %29
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i64*, i64** %6
%20 = load i32*, i32** %4
%21 = load i32*, i32** %5
%22 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64* %19, i32* %20, i32* %21)
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 (i8*, ...) @log_msg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %13
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/var/lib/dsme/boot_count\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [45 x i8] c"Could not open /var/lib/dsme/boot_count: %s\0A\00"
@errno = global i32 0
@.str.3 = [10 x i8] c"%lu %u %u\00"
@.str.4 = [44 x i8] c"Error reading file /var/lib/dsme/boot_count\00"
define void @read_loop_counts(i32* %0, i32* %1, i64* %2) {
store i32 0, i32* %0
store i32 0, i32* %1
store i64 0, i64* %2
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 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 %10
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 (i8*, ...) @log_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %17
10: ; preds = %3
%11 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64* %2, i32* %0, i32* %1)
%12 = icmp eq i32 %11, 3
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (i8*, ...) @log_msg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @fclose(i32* %4)
br label %17
17: ; preds = %15, %6
ret void
}