#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned long long strtoull(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned long long get_kernel_seqnum() {
  FILE *fp;
  char filename[64];
  char seqnum[64];
  strcpy(filename, "/sys/kernel/uevent_seqnum");
  fp = fopen(filename, "r");
  if (fp == NULL)
    return 0;
  fread(seqnum, 1, 64, fp);
  fclose(fp);
  return strtoull(seqnum, NULL, 0);
}


x86 assembly (clang, -O0):
<get_kernel_seqnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x50(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <get_kernel_seqnum+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11d0 <get_kernel_seqnum+0x80>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1040 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x90(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoull@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_kernel_seqnum>:
push   %r14
push   %rbx
sub    $0x88,%rsp
lea    0xe9f(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b3 <get_kernel_seqnum+0x63>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoull@plt>
jmp    11b5 <get_kernel_seqnum+0x65>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/sys/kernel/uevent_seqnum\00"
@.str.1 = [2 x i8] c"r\00"
define i64 @get_kernel_seqnum() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca [64 x i8]
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %0
store i64 0, i64* %1
br label %20
12: ; preds = %0
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32 @fread(i8* %13, i32 1, i32 64, i32* %14)
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%19 = call i64 @strtoull(i8* %18, i32* null, i32 0)
store i64 %19, i64* %1
br label %20
20: ; preds = %12, %11
%21 = load i64, i64* %1
ret i64 %21
}

LLVM IR (-O2):
@.str = [26 x i8] c"/sys/kernel/uevent_seqnum\00"
@.str.1 = [2 x i8] c"r\00"
define i64 @get_kernel_seqnum() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = call i32 @fread(i8* %4, i32 1, i32 64, i32* %6)
%10 = call i32 @fclose(i32* %6)
%11 = call i64 @strtoull(i8* nocapture %4, i32* null, i32 0)
br label %12
12: ; preds = %0, %8
%13 = phi i64 [ %11, %8 ], [ 0, %0 ]
ret i64 %13
}