#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 PATH_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned int *, int, int, int /*<<< orphan*/ *);
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int get_win_count() {
  char *homedir = getenv("HOME");
  if (!homedir)
    return 0;
  char configname[PATH_MAX];
  strcpy(configname, homedir);
  strcat(configname, "/."
                     "kabusol"
                     "/wincount");
  FILE *cffile = fopen(configname, "rb");
  if (!cffile)
    return 0;
  unsigned int value = 0;
  int r = fread(&value, 4, 1, cffile);
  fclose(cffile);
  if (r == 0)
    return 0;
  else
    return value;
}


x86 assembly (clang, -O0):
<get_win_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118f <get_win_count+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1261 <get_win_count+0x101>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1206 <get_win_count+0xa6>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    125a <get_win_count+0xfa>
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x34(%rbp)
jne    124d <get_win_count+0xed>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    125a <get_win_count+0xfa>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_win_count>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f9 <get_win_count+0x99>
mov    %rsp,%r15
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fd <get_win_count+0x9d>
mov    %rax,%r14
movl   $0x0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <fclose@plt>
test   %ebx,%ebx
je     11ff <get_win_count+0x9f>
mov    -0x1c(%rbp),%ebx
jmp    11ff <get_win_count+0x9f>
xor    %ebx,%ebx
jmp    1202 <get_win_count+0xa2>
xor    %ebx,%ebx
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@PATH_MAX = global i32 0
@.str.1 = [19 x i8] c"/.kabusol/wincount\00"
@.str.2 = [3 x i8] c"rb\00"
define i32 @get_win_count() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %0
store i32 0, i32* %1
br label %37
13: ; preds = %0
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %3
%17 = alloca i8, i64 %15
store i64 %15, i64* %4
%18 = load i8*, i8** %2
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %5
%22 = load i32*, i32** %5
%23 = icmp ne i32* %22, null
br i1 %23, label %25, label %24
24: ; preds = %13
store i32 0, i32* %1
store i32 1, i32* %6
br label %35
25: ; preds = %13
store i32 0, i32* %7
%26 = load i32*, i32** %5
%27 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %26)
store i32 %27, i32* %8
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 0, i32* %1
store i32 1, i32* %6
br label %35
33: ; preds = %25
%34 = load i32, i32* %7
store i32 %34, i32* %1
store i32 1, i32* %6
br label %35
35: ; preds = %33, %32, %24
%36 = load i8*, i8** %3
br label %37
37: ; preds = %35, %12
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@PATH_MAX = global i32 0
@.str.1 = [19 x i8] c"/.kabusol/wincount\00"
@.str.2 = [3 x i8] c"rb\00"
define i32 @get_win_count() {
%1 = alloca i32
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %22, label %4
4: ; preds = %0
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @strcpy(i8* %8, i8* %2)
%10 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %20, label %13
13: ; preds = %4
%14 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%15 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %11)
%16 = call i32 @fclose(i32* %11)
%17 = icmp eq i32 %15, 0
%18 = load i32, i32* %1
%19 = select i1 %17, i32 0, i32 %18
br label %20
20: ; preds = %4, %13
%21 = phi i32 [ %19, %13 ], [ 0, %4 ]
br label %22
22: ; preds = %0, %20
%23 = phi i32 [ %21, %20 ], [ 0, %0 ]
ret i32 %23
}