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

/* Variables and functions */
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
int asprintf(char **, char *);
int creat(char *, int);
char *strchr(char const *, char);
int /*<<< orphan*/ unlink(char *);
bool file_check_config(const char *cfgstring, char **reason) {
  char *path;
  int fd;
  path = strchr(cfgstring, '/');
  if (!path) {
    if (asprintf(reason, "No path found") == -1)
      *reason = NULL;
    return false;
  }
  path += 1;
  if (access(path, W_OK) != -1)
    return true;
  fd = creat(path, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    if (asprintf(reason, "Could not create file") == -1)
      *reason = NULL;
    return false;
  }
  unlink(path);
  return true;
}


x86 assembly (clang, -O0):
<file_check_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ad <file_check_config+0x5d>
mov    -0x18(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11a1 <file_check_config+0x51>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1248 <file_check_config+0xf8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11e0 <file_check_config+0x90>
movl   $0x1,-0x4(%rbp)
jmp    1248 <file_check_config+0xf8>
mov    -0x20(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    0x2dec(%rip),%rax
or     (%rax),%esi
call   1070 <creat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1238 <file_check_config+0xe8>
mov    -0x18(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    122c <file_check_config+0xdc>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1248 <file_check_config+0xf8>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_check_config>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b1 <file_check_config+0x61>
mov    %rax,%rbx
add    $0x1,%rbx
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
jne    11ce <file_check_config+0x7e>
mov    0x2e41(%rip),%rax
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1070 <creat@plt>
cmp    $0xffffffff,%eax
je     11d5 <file_check_config+0x85>
mov    %rbx,%rdi
call   1030 <unlink@plt>
jmp    11ce <file_check_config+0x7e>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
call   1050 <asprintf@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    11ce <file_check_config+0x7e>
movq   $0x0,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe32(%rip),%rsi
jmp    11b8 <file_check_config+0x68>

LLVM IR (-O0):
@.str = [14 x i8] c"No path found\00"
@W_OK = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [22 x i8] c"Could not create file\00"
define i32 @file_check_config(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = load i8*, i8** %4
%9 = call i8* @strchr(i8* %8, i8 signext 47)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = call i32 @asprintf(i8** %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i8**, i8*** %5
store i8* null, i8** %17
br label %18
18: ; preds = %16, %12
store i32 0, i32* %3
br label %45
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = load i32, i32* @W_OK
%24 = call i32 @access(i8* %22, i32 %23)
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %3
br label %45
27: ; preds = %19
%28 = load i8*, i8** %6
%29 = load i32, i32* @S_IRUSR
%30 = load i32, i32* @S_IWUSR
%31 = or i32 %29, %30
%32 = call i32 @creat(i8* %28, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %27
%36 = load i8**, i8*** %5
%37 = call i32 @asprintf(i8** %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i8**, i8*** %5
store i8* null, i8** %40
br label %41
41: ; preds = %39, %35
store i32 0, i32* %3
br label %45
42: ; preds = %27
%43 = load i8*, i8** %6
%44 = call i32 @unlink(i8* %43)
store i32 1, i32* %3
br label %45
45: ; preds = %42, %41, %26, %18
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"No path found\00"
@W_OK = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [22 x i8] c"Could not create file\00"
define i32 @file_check_config(i8* %0, i8** %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %26
8: ; preds = %5
store i8* null, i8** %1
br label %26
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %3, i64 1
%11 = load i32, i32* @W_OK
%12 = tail call i32 @access(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %16, %15
%18 = tail call i32 @creat(i8* %10, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = tail call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20
store i8* null, i8** %1
br label %26
24: ; preds = %14
%25 = tail call i32 @unlink(i8* %10)
br label %26
26: ; preds = %20, %23, %9, %5, %8, %24
%27 = phi i32 [ 1, %24 ], [ 0, %8 ], [ 0, %5 ], [ 1, %9 ], [ 0, %23 ], [ 0, %20 ]
ret i32 %27
}