#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 /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strdup(char const *);
char *strtok_r(char *, char *, char **);
int parse_promises(const char *promises, unsigned int *scope_flags) {
  unsigned int flags = 0;
  char *promises_copy = strdup(promises);
  char *strtok_arg0 = promises_copy;
  char *saveptr = NULL;
  char *item = NULL;
  while ((item = strtok_r(strtok_arg0, " ", &saveptr))) {
    strtok_arg0 = NULL;
    if (!strcmp(item, "stdio")) {
      flags |= (1 << 0);
    } else if (!strcmp(item, "rpath")) {
      flags |= (1 << 1);
    } else if (!strcmp(item, "wpath")) {
      flags |= (1 << 2);
    } else if (!strcmp(item, "cpath")) {
      flags |= (1 << 3);
    } else if (!strcmp(item, "dpath")) {
      flags |= (1 << 4);
    } else if (!strcmp(item, "inet")) {
      flags |= (1 << 5);
    } else if (!strcmp(item, "dns_experimental")) {
      flags |= (1 << 6);
    } else {
      errno = EINVAL;
      free(promises_copy);
      return -1;
    }
  }
  *scope_flags = flags;
  free(promises_copy);
  return 0;
}


x86 assembly (clang, -O0):
<parse_promises>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1301 <parse_promises+0x1c1>
movq   $0x0,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11cd <parse_promises+0x8d>
mov    -0x1c(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12fc <parse_promises+0x1bc>
mov    -0x40(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f4 <parse_promises+0xb4>
mov    -0x1c(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    12f7 <parse_promises+0x1b7>
mov    -0x40(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    121b <parse_promises+0xdb>
mov    -0x1c(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    12f2 <parse_promises+0x1b2>
mov    -0x40(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1242 <parse_promises+0x102>
mov    -0x1c(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    12ed <parse_promises+0x1ad>
mov    -0x40(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1269 <parse_promises+0x129>
mov    -0x1c(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e8 <parse_promises+0x1a8>
mov    -0x40(%rbp),%rdi
lea    0xdac(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1290 <parse_promises+0x150>
mov    -0x1c(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e3 <parse_promises+0x1a3>
mov    -0x40(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12b7 <parse_promises+0x177>
mov    -0x1c(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x1c(%rbp)
jmp    12de <parse_promises+0x19e>
mov    0x2d1a(%rip),%rax
mov    (%rax),%ecx
mov    0x2d19(%rip),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131a <parse_promises+0x1da>
jmp    12e3 <parse_promises+0x1a3>
jmp    12e8 <parse_promises+0x1a8>
jmp    12ed <parse_promises+0x1ad>
jmp    12f2 <parse_promises+0x1b2>
jmp    12f7 <parse_promises+0x1b7>
jmp    12fc <parse_promises+0x1bc>
jmp    117c <parse_promises+0x3c>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_promises>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
call   1060 <strdup@plt>
movq   $0x0,(%rsp)
lea    0xe99(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
call   1040 <strtok_r@plt>
mov    $0x0,%r15d
test   %rax,%rax
je     1292 <parse_promises+0x152>
mov    %rax,%r12
xor    %r15d,%r15d
lea    0xe6f(%rip),%r13
lea    0xe66(%rip),%rbx
mov    %rsp,%rbp
lea    0xe64(%rip),%r14
jmp    11d1 <parse_promises+0x91>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%ecx
or     %ecx,%r15d
xor    %edi,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <strtok_r@plt>
mov    %rax,%r12
test   %rax,%rax
je     1292 <parse_promises+0x152>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b0 <parse_promises+0x70>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1260 <parse_promises+0x120>
mov    %r12,%rdi
lea    0xe15(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     126a <parse_promises+0x12a>
mov    %r12,%rdi
lea    0xe08(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1274 <parse_promises+0x134>
mov    %r12,%rdi
lea    0xdfb(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     127e <parse_promises+0x13e>
mov    %r12,%rdi
lea    0xdee(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1288 <parse_promises+0x148>
mov    %r12,%rdi
lea    0xde0(%rip),%rsi
call   1050 <strcmp@plt>
mov    $0x40,%ecx
test   %eax,%eax
je     11b5 <parse_promises+0x75>
jmp    12b7 <parse_promises+0x177>
nopl   0x0(%rax)
mov    $0x2,%ecx
jmp    11b5 <parse_promises+0x75>
mov    $0x4,%ecx
jmp    11b5 <parse_promises+0x75>
mov    $0x8,%ecx
jmp    11b5 <parse_promises+0x75>
mov    $0x10,%ecx
jmp    11b5 <parse_promises+0x75>
mov    $0x20,%ecx
jmp    11b5 <parse_promises+0x75>
mov    0x8(%rsp),%rax
mov    %r15d,(%rax)
xor    %ebx,%ebx
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    0x2d19(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
jmp    129c <parse_promises+0x15c>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [6 x i8] c"stdio\00"
@.str.2 = [6 x i8] c"rpath\00"
@.str.3 = [6 x i8] c"wpath\00"
@.str.4 = [6 x i8] c"cpath\00"
@.str.5 = [6 x i8] c"dpath\00"
@.str.6 = [5 x i8] c"inet\00"
@.str.7 = [17 x i8] c"dns_experimental\00"
@EINVAL = global i32 0
@errno = global i32 0
define i32 @parse_promises(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%11 = load i8*, i8** %4
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
store i8* %13, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
br label %14
14: ; preds = %77, %2
%15 = load i8*, i8** %8
%16 = call i8* @strtok_r(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %16, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %78
18: ; preds = %14
store i8* null, i8** %8
%19 = load i8*, i8** %10
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %6
%24 = or i32 %23, 1
store i32 %24, i32* %6
br label %77
25: ; preds = %18
%26 = load i8*, i8** %10
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i32, i32* %6
%31 = or i32 %30, 2
store i32 %31, i32* %6
br label %76
32: ; preds = %25
%33 = load i8*, i8** %10
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* %6
%38 = or i32 %37, 4
store i32 %38, i32* %6
br label %75
39: ; preds = %32
%40 = load i8*, i8** %10
%41 = call i32 @strcmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp ne i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %39
%44 = load i32, i32* %6
%45 = or i32 %44, 8
store i32 %45, i32* %6
br label %74
46: ; preds = %39
%47 = load i8*, i8** %10
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = load i32, i32* %6
%52 = or i32 %51, 16
store i32 %52, i32* %6
br label %73
53: ; preds = %46
%54 = load i8*, i8** %10
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %53
%58 = load i32, i32* %6
%59 = or i32 %58, 32
store i32 %59, i32* %6
br label %72
60: ; preds = %53
%61 = load i8*, i8** %10
%62 = call i32 @strcmp(i8* %61, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %60
%65 = load i32, i32* %6
%66 = or i32 %65, 64
store i32 %66, i32* %6
br label %71
67: ; preds = %60
%68 = load i32, i32* @EINVAL
store i32 %68, i32* @errno
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
store i32 -1, i32* %3
br label %83
71: ; preds = %64
br label %72
72: ; preds = %71, %57
br label %73
73: ; preds = %72, %50
br label %74
74: ; preds = %73, %43
br label %75
75: ; preds = %74, %36
br label %76
76: ; preds = %75, %29
br label %77
77: ; preds = %76, %22
br label %14
78: ; preds = %14
%79 = load i32, i32* %6
%80 = load i32*, i32** %5
store i32 %79, i32* %80
%81 = load i8*, i8** %7
%82 = call i32 @free(i8* %81)
store i32 0, i32* %3
br label %83
83: ; preds = %78, %67
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [6 x i8] c"stdio\00"
@.str.2 = [6 x i8] c"rpath\00"
@.str.3 = [6 x i8] c"wpath\00"
@.str.4 = [6 x i8] c"cpath\00"
@.str.5 = [6 x i8] c"dpath\00"
@.str.6 = [5 x i8] c"inet\00"
@.str.7 = [17 x i8] c"dns_experimental\00"
@EINVAL = global i32 0
@errno = global i32 0
define i32 @parse_promises(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = tail call i8* @strdup(i8* %0)
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = call i8* @strtok_r(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %38, label %8
8: ; preds = %2, %33
%9 = phi i8* [ %36, %33 ], [ %6, %2 ]
%10 = phi i32 [ %35, %33 ], [ 0, %2 ]
%11 = call i32 @strcmp(i8* %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %33, label %13
13: ; preds = %8
%14 = call i32 @strcmp(i8* %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %13
%17 = call i32 @strcmp(i8* %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %33, label %19
19: ; preds = %16
%20 = call i32 @strcmp(i8* %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %19
%23 = call i32 @strcmp(i8* %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %22
%26 = call i32 @strcmp(i8* %9, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = call i32 @strcmp(i8* %9, i8* dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = load i32, i32* @EINVAL
store i32 %32, i32* @errno
br label %40
33: ; preds = %28, %25, %22, %19, %16, %13, %8
%34 = phi i32 [ 1, %8 ], [ 2, %13 ], [ 4, %16 ], [ 8, %19 ], [ 16, %22 ], [ 32, %25 ], [ 64, %28 ]
%35 = or i32 %10, %34
%36 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %8
38: ; preds = %33, %2
%39 = phi i32 [ 0, %2 ], [ %35, %33 ]
store i32 %39, i32* %1
br label %40
40: ; preds = %38, %31
%41 = phi i32 [ -1, %31 ], [ 0, %38 ]
%42 = call i32 @free(i8* %4)
ret i32 %41
}