#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 R_OK;
int W_OK;
int access(char *, int);
int asprintf(char **, char *);
char *strchr(char const *, char);
bool qcow_check_config(const char *cfgstring, char **reason) {
  char *path;
  path = strchr(cfgstring, '/');
  if (!path) {
    if (asprintf(reason, "No path found") == -1)
      *reason = NULL;
    return false;
  }
  path += 1;
  if (access(path, R_OK | W_OK) == -1) {
    if (asprintf(reason, "File not present, or not writable") == -1)
      *reason = NULL;
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<qcow_check_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118d <qcow_check_config+0x5d>
mov    -0x18(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    1181 <qcow_check_config+0x51>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f4 <qcow_check_config+0xc4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
or     (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    11ed <qcow_check_config+0xbd>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11e1 <qcow_check_config+0xb1>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f4 <qcow_check_config+0xc4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qcow_check_config>:
push   %rbx
mov    %rsi,%rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     116f <qcow_check_config+0x3f>
add    $0x1,%rax
mov    0x2e8a(%rip),%rcx
mov    0x2e93(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %rax,%rdi
call   1050 <access@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     1178 <qcow_check_config+0x48>
pop    %rbx
ret
lea    0xe8a(%rip),%rsi
jmp    117f <qcow_check_config+0x4f>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <asprintf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    116d <qcow_check_config+0x3d>
movq   $0x0,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"No path found\00"
@R_OK = global i32 0
@W_OK = global i32 0
@.str.1 = [34 x i8] c"File not present, or not writable\00"
define i32 @qcow_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 %8
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 %18, label %19
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = load i32, i32* @R_OK
%11 = load i32, i32* @W_OK
%12 = or i32 %11, %10
%13 = tail call i32 @access(i8* %9, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = tail call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %15, %5
store i8* null, i8** %1
br label %19
19: ; preds = %18, %8, %15, %5
%20 = phi i32 [ 0, %5 ], [ 0, %15 ], [ 1, %8 ], [ 0, %18 ]
ret i32 %20
}