#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 */
char *dirname(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ is_only_root_writable(char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char const *);
int check_configuration_permissions(const char *file_name) {
  char *dir = strdup(file_name);
  char *buffer = dir;
  do {
    if (!is_only_root_writable(dir)) {
      free(buffer);
      return -1;
    }
    dir = dirname(dir);
  } while (strcmp(dir, "/") != 0);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<check_configuration_permissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <is_only_root_writable@plt>
cmp    $0x0,%eax
jne    1198 <check_configuration_permissions+0x48>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <check_configuration_permissions+0x7f>
mov    -0x18(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1171 <check_configuration_permissions+0x21>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_configuration_permissions>:
push   %r15
push   %r14
push   %rbx
call   1070 <strdup@plt>
mov    %rax,%r14
lea    0xe9c(%rip),%r15
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <is_only_root_writable@plt>
test   %eax,%eax
je     119b <check_configuration_permissions+0x4b>
mov    %rbx,%rdi
call   1050 <dirname@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1170 <check_configuration_permissions+0x20>
xor    %ebx,%ebx
jmp    11a0 <check_configuration_permissions+0x50>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @check_configuration_permissions(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strdup(i8* %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
store i8* %8, i8** %5
br label %9
9: ; preds = %19, %1
%10 = load i8*, i8** %4
%11 = call i32 @is_only_root_writable(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = call i32 @free(i8* %14)
store i32 -1, i32* %2
br label %26
16: ; preds = %9
%17 = load i8*, i8** %4
%18 = call i8* @dirname(i8* %17)
store i8* %18, i8** %4
br label %19
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %9, label %23
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = call i32 @free(i8* %24)
store i32 0, i32* %2
br label %26
26: ; preds = %23, %13
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @check_configuration_permissions(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
br label %3
3: ; preds = %7, %1
%4 = phi i8* [ %2, %1 ], [ %8, %7 ]
%5 = tail call i32 @is_only_root_writable(i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call i8* @dirname(i8* %4)
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %7, %3
%12 = phi i32 [ -1, %3 ], [ 0, %7 ]
%13 = tail call i32 @free(i8* %2)
ret i32 %12
}