#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 */
scalar_t__ piece(char *, char, char *, int);
int session_get_session_folder_access_ok(char *, char *, char *, char *,
                                         char *);
scalar_t__ strcmp(char *, char *);
int session_access_folder(char *application_name, char *session,
                          char *folder_name_comma_list_string, char *role_name,
                          char *permission) {
  char folder_name[128];
  int access_ok = 0;
  int i;
  if (strcmp(permission, "view") == 0)
    permission = "lookup";
  for (i = 0; piece(folder_name, ',', folder_name_comma_list_string, i); i++) {
    access_ok = session_get_session_folder_access_ok(
        application_name, session, folder_name, role_name, permission);
    if (!access_ok && strcmp(permission, "lookup") == 0) {
      access_ok = session_get_session_folder_access_ok(
          application_name, session, folder_name, role_name, "update");
    }
    if (!access_ok && (strcmp(permission, "update") == 0 ||
                       strcmp(permission, "lookup") == 0)) {
      access_ok = session_get_session_folder_access_ok(
          application_name, session, folder_name, role_name, "insert");
    }
    if (!access_ok)
      return 0;
  }
  return access_ok;
}


x86 assembly (clang, -O0):
<session_access_folder>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0xb4(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    117e <session_access_folder+0x4e>
lea    0xe8b(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xb8(%rbp),%ecx
mov    $0x2c,%esi
call   1050 <piece@plt>
cmp    $0x0,%rax
je     12b3 <session_access_folder+0x183>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <session_get_session_folder_access_ok@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jne    121b <session_access_folder+0xeb>
mov    -0x30(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    121b <session_access_folder+0xeb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdfc(%rip),%r8
call   1040 <session_get_session_folder_access_ok@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jne    1281 <session_access_folder+0x151>
mov    -0x30(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     125c <session_access_folder+0x12c>
mov    -0x30(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1281 <session_access_folder+0x151>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd9d(%rip),%r8
call   1040 <session_get_session_folder_access_ok@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jne    129a <session_access_folder+0x16a>
movl   $0x0,-0x4(%rbp)
jmp    12bc <session_access_folder+0x18c>
jmp    129f <session_access_folder+0x16f>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1188 <session_access_folder+0x58>
mov    -0xb4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<session_access_folder>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r8,%rbp
mov    %rcx,(%rsp)
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xea8(%rip),%rsi
mov    %r8,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
lea    0xe9b(%rip),%rbx
cmovne %rbp,%rbx
lea    0x10(%rsp),%rdi
mov    $0x2c,%esi
mov    %r14,0x8(%rsp)
mov    %r14,%rdx
xor    %ecx,%ecx
call   1050 <piece@plt>
test   %rax,%rax
je     126c <session_access_folder+0x13c>
mov    $0x1,%ebp
lea    0x10(%rsp),%r14
jmp    11e4 <session_access_folder+0xb4>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    (%rsp),%rcx
lea    0xe5f(%rip),%r8
call   1040 <session_get_session_folder_access_ok@plt>
mov    %eax,%r15d
test   %eax,%eax
je     126c <session_access_folder+0x13c>
mov    %r14,%rdi
mov    $0x2c,%esi
mov    0x8(%rsp),%rdx
mov    %ebp,%ecx
call   1050 <piece@plt>
add    $0x1,%ebp
test   %rax,%rax
je     126f <session_access_folder+0x13f>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    (%rsp),%rcx
mov    %rbx,%r8
call   1040 <session_get_session_folder_access_ok@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11c4 <session_access_folder+0x94>
mov    %rbx,%rdi
lea    0xdfb(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1246 <session_access_folder+0x116>
mov    %rbx,%rdi
lea    0xdee(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11a0 <session_access_folder+0x70>
mov    %rbx,%rdi
lea    0xdcf(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11a0 <session_access_folder+0x70>
jmp    126c <session_access_folder+0x13c>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    (%rsp),%rcx
lea    0xdb2(%rip),%r8
call   1040 <session_get_session_folder_access_ok@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11c4 <session_access_folder+0x94>
jmp    1214 <session_access_folder+0xe4>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"view\00"
@.str.1 = [7 x i8] c"lookup\00"
@.str.2 = [7 x i8] c"update\00"
@.str.3 = [7 x i8] c"insert\00"
define i32 @session_access_folder(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca [128 x i8]
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 0, i32* %13
%15 = load i8*, i8** %11
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %19
19: ; preds = %18, %5
store i32 0, i32* %14
br label %20
20: ; preds = %67, %19
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%22 = load i8*, i8** %9
%23 = load i32, i32* %14
%24 = call i64 @piece(i8* %21, i8 signext 44, i8* %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %70
26: ; preds = %20
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%30 = load i8*, i8** %10
%31 = load i8*, i8** %11
%32 = call i32 @session_get_session_folder_access_ok(i8* %27, i8* %28, i8* %29, i8* %30, i8* %31)
store i32 %32, i32* %13
%33 = load i32, i32* %13
%34 = icmp ne i32 %33, 0
br i1 %34, label %45, label %35
35: ; preds = %26
%36 = load i8*, i8** %11
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load i8*, i8** %7
%41 = load i8*, i8** %8
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%43 = load i8*, i8** %10
%44 = call i32 @session_get_session_folder_access_ok(i8* %40, i8* %41, i8* %42, i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 %44, i32* %13
br label %45
45: ; preds = %39, %35, %26
%46 = load i32, i32* %13
%47 = icmp ne i32 %46, 0
br i1 %47, label %62, label %48
48: ; preds = %45
%49 = load i8*, i8** %11
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %48
%53 = load i8*, i8** %11
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %52, %48
%57 = load i8*, i8** %7
%58 = load i8*, i8** %8
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%60 = load i8*, i8** %10
%61 = call i32 @session_get_session_folder_access_ok(i8* %57, i8* %58, i8* %59, i8* %60, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 %61, i32* %13
br label %62
62: ; preds = %56, %52, %45
%63 = load i32, i32* %13
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %62
store i32 0, i32* %6
br label %72
66: ; preds = %62
br label %67
67: ; preds = %66
%68 = load i32, i32* %14
%69 = add nsw i32 %68, 1
store i32 %69, i32* %14
br label %20
70: ; preds = %20
%71 = load i32, i32* %13
store i32 %71, i32* %6
br label %72
72: ; preds = %70, %65
%73 = load i32, i32* %6
ret i32 %73
}

LLVM IR (-O2):
@.str = [5 x i8] c"view\00"
@.str.1 = [7 x i8] c"lookup\00"
@.str.2 = [7 x i8] c"update\00"
@.str.3 = [7 x i8] c"insert\00"
define i32 @session_access_folder(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%8 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4
%11 = call i64 @piece(i8* %7, i8 signext 44, i8* %2, i32 0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %37, label %13
13: ; preds = %5, %32
%14 = phi i32 [ %34, %32 ], [ 0, %5 ]
%15 = call i32 @session_get_session_folder_access_ok(i8* %0, i8* %1, i8* %7, i8* %3, i8* %10)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @session_get_session_folder_access_ok(i8* %0, i8* %1, i8* %7, i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %17, %20
%24 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %23, %26
%30 = call i32 @session_get_session_folder_access_ok(i8* %0, i8* %1, i8* %7, i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %13, %20, %29
%33 = phi i32 [ %30, %29 ], [ %21, %20 ], [ %15, %13 ]
%34 = add nuw nsw i32 %14, 1
%35 = call i64 @piece(i8* %7, i8 signext 44, i8* %2, i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %13
37: ; preds = %29, %32, %26, %5
%38 = phi i32 [ 0, %5 ], [ 0, %26 ], [ %33, %32 ], [ 0, %29 ]
ret i32 %38
}