#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*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ write_preferences();
int check_auth(void) {
  FILE *fp = NULL;
  int success = 0;
  puts("Checking authentication...");
  fp = fopen("preferences.txt", "r");
  if (fp == NULL) {
    perror("Unreadable preferences file");
    write_preferences();
  }
  return success;
}


x86 assembly (clang, -O0):
<check_auth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1198 <check_auth+0x58>
lea    0xea1(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1040 <write_preferences@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_auth>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xec7(%rip),%rdi
lea    0xed0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1169 <check_auth+0x29>
xor    %eax,%eax
pop    %rcx
ret
lea    0xebd(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1040 <write_preferences@plt>
jmp    1165 <check_auth+0x25>

LLVM IR (-O0):
@.str = [27 x i8] c"Checking authentication...\00"
@.str.1 = [16 x i8] c"preferences.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"Unreadable preferences file\00"
define i32 @check_auth() {
%1 = alloca i32*
%2 = alloca i32
store i32* null, i32** %1
store i32 0, i32* %2
%3 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (...) @write_preferences()
br label %10
10: ; preds = %7, %0
%11 = load i32, i32* %2
ret i32 %11
}

LLVM IR (-O2):
@.str = [27 x i8] c"Checking authentication...\00"
@.str.1 = [16 x i8] c"preferences.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"Unreadable preferences file\00"
define i32 @check_auth() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 (...) @write_preferences()
br label %7
7: ; preds = %4, %0
ret i32 0
}