#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 add_dir_rule(char *, char *, unsigned int);
unsigned int parse_dir_option(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strchr(char *, char);
scalar_t__ strlen(char *);
char *xmalloc(scalar_t__);
char *xstrdup(char *);
int set_dir_action(char *arg) {
  arg = xstrdup(arg);
  char *colon = strchr(arg, ':');
  unsigned int flags = 0;
  while (colon) {
    *colon++ = 0;
    char *next = strchr(colon, ':');
    if (next)
      *next = 0;
    flags |= parse_dir_option(colon);
    colon = next;
  }
  char *eq = strchr(arg, '=');
  if (eq) {
    *eq++ = 0;
    return add_dir_rule(arg, (*eq ? eq : NULL), flags);
  } else {
    char *out = xmalloc(1 + strlen(arg) + 1);
    sprintf(out, "/%s", arg);
    return add_dir_rule(arg, out, flags);
  }
}


x86 assembly (clang, -O0):
<set_dir_action>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ff <set_dir_action+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e3 <set_dir_action+0x73>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1070 <parse_dir_option@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11a2 <set_dir_action+0x32>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1276 <set_dir_action+0x106>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1253 <set_dir_action+0xe3>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    125e <set_dir_action+0xee>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    125e <set_dir_action+0xee>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <add_dir_rule@plt>
mov    %eax,-0x4(%rbp)
jmp    12ba <set_dir_action+0x14a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd5e(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <add_dir_rule@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_dir_action>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1060 <xstrdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f0 <set_dir_action+0x80>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f5 <set_dir_action+0x85>
mov    %rax,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%r15)
mov    %rbx,%rdi
call   1070 <parse_dir_option@plt>
or     %eax,%ebp
movb   $0x0,(%r15)
mov    %r15,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c0 <set_dir_action+0x50>
jmp    11f7 <set_dir_action+0x87>
xor    %r15d,%r15d
jmp    1205 <set_dir_action+0x95>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1070 <parse_dir_option@plt>
mov    %eax,%r15d
or     %ebp,%r15d
mov    %r14,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     122d <set_dir_action+0xbd>
mov    %rax,%rcx
add    $0x1,%rcx
movb   $0x0,(%rax)
xor    %ebx,%ebx
cmpb   $0x0,0x1(%rax)
cmovne %rcx,%rbx
jmp    1253 <set_dir_action+0xe3>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x2(%rax),%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
lea    0xdb8(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <add_dir_rule@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"/%s\00"
define i32 @set_dir_action(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @xstrdup(i8* %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i8* @strchr(i8* %11, i8 signext 58)
store i8* %12, i8** %4
store i32 0, i32* %5
br label %13
13: ; preds = %25, %1
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
store i8 0, i8* %17
%19 = load i8*, i8** %4
%20 = call i8* @strchr(i8* %19, i8 signext 58)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = load i8*, i8** %6
store i8 0, i8* %24
br label %25
25: ; preds = %23, %16
%26 = load i8*, i8** %4
%27 = call i32 @parse_dir_option(i8* %26)
%28 = load i32, i32* %5
%29 = or i32 %28, %27
store i32 %29, i32* %5
%30 = load i8*, i8** %6
store i8* %30, i8** %4
br label %13
31: ; preds = %13
%32 = load i8*, i8** %3
%33 = call i8* @strchr(i8* %32, i8 signext 61)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %51
36: ; preds = %31
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %7
store i8 0, i8* %37
%39 = load i8*, i8** %3
%40 = load i8*, i8** %7
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = load i8*, i8** %7
br label %47
46: ; preds = %36
br label %47
47: ; preds = %46, %44
%48 = phi i8* [ %45, %44 ], [ null, %46 ]
%49 = load i32, i32* %5
%50 = call i32 @add_dir_rule(i8* %39, i8* %48, i32 %49)
store i32 %50, i32* %2
br label %64
51: ; preds = %31
%52 = load i8*, i8** %3
%53 = call i64 @strlen(i8* %52)
%54 = add nsw i64 1, %53
%55 = add nsw i64 %54, 1
%56 = call i8* @xmalloc(i64 %55)
store i8* %56, i8** %8
%57 = load i8*, i8** %8
%58 = load i8*, i8** %3
%59 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %58)
%60 = load i8*, i8** %3
%61 = load i8*, i8** %8
%62 = load i32, i32* %5
%63 = call i32 @add_dir_rule(i8* %60, i8* %61, i32 %62)
store i32 %63, i32* %2
br label %64
64: ; preds = %51, %47
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
@.str = [4 x i8] c"/%s\00"
define i32 @set_dir_action(i8* %0) {
%2 = tail call i8* @xstrdup(i8* %0)
%3 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %3, i64 1
store i8 0, i8* %3
%7 = tail call i8* @strchr(i8* %6, i8 signext 58)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %5, %9
%10 = phi i8* [ %16, %9 ], [ %7, %5 ]
%11 = phi i8* [ %15, %9 ], [ %6, %5 ]
%12 = phi i32 [ %14, %9 ], [ 0, %5 ]
store i8 0, i8* %10
%13 = tail call i32 @parse_dir_option(i8* %11)
%14 = or i32 %13, %12
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 0, i8* %10
%16 = tail call i8* @strchr(i8* %15, i8 signext 58)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %5
%19 = phi i32 [ 0, %5 ], [ %14, %9 ]
%20 = phi i8* [ %6, %5 ], [ %15, %9 ]
%21 = tail call i32 @parse_dir_option(i8* %20)
%22 = or i32 %21, %19
br label %23
23: ; preds = %18, %1
%24 = phi i32 [ 0, %1 ], [ %22, %18 ]
%25 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 61)
%26 = icmp eq i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %25
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
%31 = select i1 %30, i8* null, i8* %28
br label %37
32: ; preds = %23
%33 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%34 = add nsw i64 %33, 2
%35 = tail call i8* @xmalloc(i64 %34)
%36 = tail call i32 @sprintf(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %37
37: ; preds = %32, %27
%38 = phi i8* [ %35, %32 ], [ %31, %27 ]
%39 = tail call i32 @add_dir_rule(i8* %2, i8* %38, i32 %24)
ret i32 %39
}