#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 check_bus_or_interface_name(char *, int /*<<< orphan*/);
int check_object_path(char *);
int /*<<< orphan*/ dbus_check_name(char *);
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int dbus_check_call_rule(const char *rule) {
  char buf[255 + 1];
  char *name_end = strchr(rule, '=');
  if (name_end == NULL)
    return 0;
  size_t name_length = (size_t)(name_end - rule);
  if (name_length > 255)
    return 0;
  strncpy(buf, rule, (size_t)name_length);
  buf[name_length] = '\0';
  if (!dbus_check_name(buf))
    return 0;
  ++name_end;
  char *interface_end = strchr(name_end, '@');
  if (interface_end == NULL)
    return check_bus_or_interface_name(name_end, 0);
  size_t interface_length = (size_t)(interface_end - name_end);
  if (interface_length > 255)
    return 0;
  if (interface_length > 0) {
    strncpy(buf, name_end, interface_length);
    buf[interface_length] = '\0';
    if (!check_bus_or_interface_name(buf, 0))
      return 0;
  }
  return check_object_path(interface_end + 1);
}


x86 assembly (clang, -O0):
<dbus_check_call_rule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    118e <dbus_check_call_rule+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    12fc <dbus_check_call_rule+0x1ac>
mov    -0x118(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x120(%rbp)
cmpq   $0xff,-0x120(%rbp)
jbe    11c0 <dbus_check_call_rule+0x70>
movl   $0x0,-0x4(%rbp)
jmp    12fc <dbus_check_call_rule+0x1ac>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x120(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x120(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1050 <dbus_check_name@plt>
cmp    $0x0,%eax
jne    1207 <dbus_check_call_rule+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    12fc <dbus_check_call_rule+0x1ac>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
mov    $0x40,%esi
call   1060 <strchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1255 <dbus_check_call_rule+0x105>
mov    -0x118(%rbp),%rdi
xor    %esi,%esi
call   1070 <check_bus_or_interface_name@plt>
mov    %eax,-0x4(%rbp)
jmp    12fc <dbus_check_call_rule+0x1ac>
mov    -0x128(%rbp),%rax
mov    -0x118(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x130(%rbp)
cmpq   $0xff,-0x130(%rbp)
jbe    128a <dbus_check_call_rule+0x13a>
movl   $0x0,-0x4(%rbp)
jmp    12fc <dbus_check_call_rule+0x1ac>
cmpq   $0x0,-0x130(%rbp)
jbe    12e9 <dbus_check_call_rule+0x199>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rsi
mov    -0x130(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x130(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
call   1070 <check_bus_or_interface_name@plt>
cmp    $0x0,%eax
jne    12e4 <dbus_check_call_rule+0x194>
movl   $0x0,-0x4(%rbp)
jmp    12fc <dbus_check_call_rule+0x1ac>
jmp    12e9 <dbus_check_call_rule+0x199>
mov    -0x128(%rbp),%rdi
add    $0x1,%rdi
call   1040 <check_object_path@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbus_check_call_rule>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbp
mov    $0x3d,%esi
call   1060 <strchr@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     121d <dbus_check_call_rule+0xcd>
mov    %rax,%r12
mov    %rax,%rbx
sub    %rbp,%rbx
cmp    $0xff,%rbx
ja     121d <dbus_check_call_rule+0xcd>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
call   1050 <dbus_check_name@plt>
test   %eax,%eax
je     121d <dbus_check_call_rule+0xcd>
add    $0x1,%r12
mov    %r12,%rdi
mov    $0x40,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1210 <dbus_check_call_rule+0xc0>
mov    %rax,%r14
mov    %rax,%rbp
sub    %r12,%rbp
cmp    $0xff,%rbp
ja     121d <dbus_check_call_rule+0xcd>
test   %rbp,%rbp
je     1202 <dbus_check_call_rule+0xb2>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbp,1)
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <check_bus_or_interface_name@plt>
test   %eax,%eax
je     121d <dbus_check_call_rule+0xcd>
add    $0x1,%r14
mov    %r14,%rdi
call   1040 <check_object_path@plt>
jmp    121a <dbus_check_call_rule+0xca>
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <check_bus_or_interface_name@plt>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dbus_check_call_rule(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @strchr(i8* %9, i8 signext 61)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 0, i32* %2
br label %72
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = load i8*, i8** %3
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp ugt i64 %20, 255
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 0, i32* %2
br label %72
23: ; preds = %14
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = load i64, i64* %6
%27 = call i32 @strncpy(i8* %24, i8* %25, i64 %26)
%28 = load i64, i64* %6
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%31 = call i32 @dbus_check_name(i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %23
store i32 0, i32* %2
br label %72
34: ; preds = %23
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
%37 = load i8*, i8** %5
%38 = call i8* @strchr(i8* %37, i8 signext 64)
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i8*, i8** %5
%43 = call i32 @check_bus_or_interface_name(i8* %42, i32 0)
store i32 %43, i32* %2
br label %72
44: ; preds = %34
%45 = load i8*, i8** %7
%46 = load i8*, i8** %5
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
store i64 %49, i64* %8
%50 = load i64, i64* %8
%51 = icmp ugt i64 %50, 255
br i1 %51, label %52, label %53
52: ; preds = %44
store i32 0, i32* %2
br label %72
53: ; preds = %44
%54 = load i64, i64* %8
%55 = icmp ugt i64 %54, 0
br i1 %55, label %56, label %68
56: ; preds = %53
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%58 = load i8*, i8** %5
%59 = load i64, i64* %8
%60 = call i32 @strncpy(i8* %57, i8* %58, i64 %59)
%61 = load i64, i64* %8
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %61
store i8 0, i8* %62
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%64 = call i32 @check_bus_or_interface_name(i8* %63, i32 0)
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %56
store i32 0, i32* %2
br label %72
67: ; preds = %56
br label %68
68: ; preds = %67, %53
%69 = load i8*, i8** %7
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = call i32 @check_object_path(i8* %70)
store i32 %71, i32* %2
br label %72
72: ; preds = %68, %66, %52, %41, %33, %22, %13
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
define i32 @dbus_check_call_rule(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%5 = icmp eq i8* %4, null
br i1 %5, label %37, label %6
6: ; preds = %1
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = icmp ugt i64 %9, 255
br i1 %10, label %37, label %11
11: ; preds = %6
%12 = call i32 @strncpy(i8* %3, i8* %0, i64 %9)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %13
%14 = call i32 @dbus_check_name(i8* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %37, label %16
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %4, i64 1
%18 = call i8* @strchr(i8* %17, i8 signext 64)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @check_bus_or_interface_name(i8* %17, i32 0)
br label %37
22: ; preds = %16
%23 = ptrtoint i8* %18 to i64
%24 = ptrtoint i8* %17 to i64
%25 = sub i64 %23, %24
%26 = icmp ugt i64 %25, 255
br i1 %26, label %37, label %27
27: ; preds = %22
%28 = icmp eq i64 %25, 0
br i1 %28, label %34, label %29
29: ; preds = %27
%30 = call i32 @strncpy(i8* %3, i8* %17, i64 %25)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %25
store i8 0, i8* %31
%32 = call i32 @check_bus_or_interface_name(i8* %3, i32 0)
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %29, %27
%35 = getelementptr inbounds i8, i8* %18, i64 1
%36 = call i32 @check_object_path(i8* %35)
br label %37
37: ; preds = %6, %11, %34, %22, %29, %20, %1
%38 = phi i32 [ 0, %1 ], [ 0, %6 ], [ 0, %11 ], [ %21, %20 ], [ %36, %34 ], [ 0, %22 ], [ 0, %29 ]
ret i32 %38
}