#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 */
struct udev_list_entry {
  int dummy;
};
struct udev_device {
  int dummy;
};

/* Variables and functions */
scalar_t__ strcmp(char const *, char const *);
struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *);
int /*<<< orphan*/ udev_device_tag(struct udev_device *, char const *, int);
char const *udev_list_entry_get_name(struct udev_list_entry *);
struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *);
int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old,
                          bool add) {
  struct udev_list_entry *list_entry;
  bool found;
  if (add && dev_old != NULL) {
    for (list_entry = udev_device_get_tags_list_entry(dev_old);
         list_entry != NULL;
         list_entry = udev_list_entry_get_next(list_entry)) {
      const char *tag_old = udev_list_entry_get_name(list_entry);
      struct udev_list_entry *list_entry_current;
      found = false;
      for (list_entry_current = udev_device_get_tags_list_entry(dev);
           list_entry_current != NULL;
           list_entry_current = udev_list_entry_get_next(list_entry_current)) {
        const char *tag = udev_list_entry_get_name(list_entry_current);
        if ((strcmp((tag), (tag_old)) == 0)) {
          found = true;
          break;
        }
      }
      if (!found)
        udev_device_tag(dev_old, tag_old, false);
    }
  }
  for (list_entry = udev_device_get_tags_list_entry(dev); list_entry != NULL;
       list_entry = udev_list_entry_get_next(list_entry))
    udev_device_tag(dev, udev_list_entry_get_name(list_entry), add);
  return 0;
}


x86 assembly (clang, -O0):
<udev_device_tag_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1238 <udev_device_tag_index+0xe8>
cmpq   $0x0,-0x10(%rbp)
je     1238 <udev_device_tag_index+0xe8>
mov    -0x10(%rbp),%rdi
call   1030 <udev_device_get_tags_list_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1233 <udev_device_tag_index+0xe3>
mov    -0x20(%rbp),%rdi
call   1070 <udev_list_entry_get_name@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <udev_device_get_tags_list_entry@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1203 <udev_device_tag_index+0xb3>
mov    -0x38(%rbp),%rdi
call   1070 <udev_list_entry_get_name@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <udev_device_tag_index+0x9c>
movl   $0x1,-0x24(%rbp)
jmp    1203 <udev_device_tag_index+0xb3>
jmp    11f1 <udev_device_tag_index+0xa1>
mov    -0x38(%rbp),%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,-0x38(%rbp)
jmp    11b1 <udev_device_tag_index+0x61>
cmpl   $0x0,-0x24(%rbp)
jne    121c <udev_device_tag_index+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1060 <udev_device_tag@plt>
jmp    1221 <udev_device_tag_index+0xd1>
mov    -0x20(%rbp),%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,-0x20(%rbp)
jmp    1185 <udev_device_tag_index+0x35>
jmp    1238 <udev_device_tag_index+0xe8>
mov    -0x8(%rbp),%rdi
call   1030 <udev_device_get_tags_list_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1282 <udev_device_tag_index+0x132>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <udev_list_entry_get_name@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1060 <udev_device_tag@plt>
mov    -0x20(%rbp),%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,-0x20(%rbp)
jmp    1245 <udev_device_tag_index+0xf5>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_device_tag_index>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rdi,%r12
test   %rsi,%rsi
je     11fa <udev_device_tag_index+0xaa>
test   %r15d,%r15d
je     11fa <udev_device_tag_index+0xaa>
mov    %rsi,%r14
mov    %rsi,%rdi
call   1030 <udev_device_get_tags_list_entry@plt>
test   %rax,%rax
je     11fa <udev_device_tag_index+0xaa>
mov    %rax,%r13
jmp    11ad <udev_device_tag_index+0x5d>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <udev_device_tag@plt>
mov    %r13,%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,%r13
test   %rax,%rax
je     11fa <udev_device_tag_index+0xaa>
mov    %r13,%rdi
call   1070 <udev_list_entry_get_name@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <udev_device_get_tags_list_entry@plt>
test   %rax,%rax
je     1190 <udev_device_tag_index+0x40>
mov    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1070 <udev_list_entry_get_name@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     119d <udev_device_tag_index+0x4d>
mov    %rbp,%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11d0 <udev_device_tag_index+0x80>
jmp    1190 <udev_device_tag_index+0x40>
mov    %r12,%rdi
call   1030 <udev_device_get_tags_list_entry@plt>
test   %rax,%rax
je     1236 <udev_device_tag_index+0xe6>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <udev_list_entry_get_name@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1060 <udev_device_tag@plt>
mov    %rbx,%rdi
call   1050 <udev_list_entry_get_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <udev_device_tag_index+0xc0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev_list_entry = type { i32 }
define i32 @udev_device_tag_index(%struct.udev_device* %0, %struct.udev_device* %1, i32 %2) {
%4 = alloca %struct.udev_device*
%5 = alloca %struct.udev_device*
%6 = alloca i32
%7 = alloca %struct.udev_list_entry*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.udev_list_entry*
%11 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %4
store %struct.udev_device* %1, %struct.udev_device** %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %55
14: ; preds = %3
%15 = load %struct.udev_device*, %struct.udev_device** %5
%16 = icmp ne %struct.udev_device* %15, null
br i1 %16, label %17, label %55
17: ; preds = %14
%18 = load %struct.udev_device*, %struct.udev_device** %5
%19 = call %struct.udev_list_entry* @udev_device_get_tags_list_entry(%struct.udev_device* %18)
store %struct.udev_list_entry* %19, %struct.udev_list_entry** %7
br label %20
20: ; preds = %51, %17
%21 = load %struct.udev_list_entry*, %struct.udev_list_entry** %7
%22 = icmp ne %struct.udev_list_entry* %21, null
br i1 %22, label %23, label %54
23: ; preds = %20
%24 = load %struct.udev_list_entry*, %struct.udev_list_entry** %7
%25 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %24)
store i8* %25, i8** %9
store i32 0, i32* %8
%26 = load %struct.udev_device*, %struct.udev_device** %4
%27 = call %struct.udev_list_entry* @udev_device_get_tags_list_entry(%struct.udev_device* %26)
store %struct.udev_list_entry* %27, %struct.udev_list_entry** %10
br label %28
28: ; preds = %40, %23
%29 = load %struct.udev_list_entry*, %struct.udev_list_entry** %10
%30 = icmp ne %struct.udev_list_entry* %29, null
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load %struct.udev_list_entry*, %struct.udev_list_entry** %10
%33 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %32)
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = load i8*, i8** %9
%36 = call i64 @strcmp(i8* %34, i8* %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 1, i32* %8
br label %43
39: ; preds = %31
br label %40
40: ; preds = %39
%41 = load %struct.udev_list_entry*, %struct.udev_list_entry** %10
%42 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %41)
store %struct.udev_list_entry* %42, %struct.udev_list_entry** %10
br label %28
43: ; preds = %38, %28
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = load %struct.udev_device*, %struct.udev_device** %5
%48 = load i8*, i8** %9
%49 = call i32 @udev_device_tag(%struct.udev_device* %47, i8* %48, i32 0)
br label %50
50: ; preds = %46, %43
br label %51
51: ; preds = %50
%52 = load %struct.udev_list_entry*, %struct.udev_list_entry** %7
%53 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %52)
store %struct.udev_list_entry* %53, %struct.udev_list_entry** %7
br label %20
54: ; preds = %20
br label %55
55: ; preds = %54, %14, %3
%56 = load %struct.udev_device*, %struct.udev_device** %4
%57 = call %struct.udev_list_entry* @udev_device_get_tags_list_entry(%struct.udev_device* %56)
store %struct.udev_list_entry* %57, %struct.udev_list_entry** %7
br label %58
58: ; preds = %67, %55
%59 = load %struct.udev_list_entry*, %struct.udev_list_entry** %7
%60 = icmp ne %struct.udev_list_entry* %59, null
br i1 %60, label %61, label %70
61: ; preds = %58
%62 = load %struct.udev_device*, %struct.udev_device** %4
%63 = load %struct.udev_list_entry*, %struct.udev_list_entry** %7
%64 = call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %63)
%65 = load i32, i32* %6
%66 = call i32 @udev_device_tag(%struct.udev_device* %62, i8* %64, i32 %65)
br label %67
67: ; preds = %61
%68 = load %struct.udev_list_entry*, %struct.udev_list_entry** %7
%69 = call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %68)
store %struct.udev_list_entry* %69, %struct.udev_list_entry** %7
br label %58
70: ; preds = %58
ret i32 0
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev_list_entry = type { i32 }
define i32 @udev_device_tag_index(%struct.udev_device* %0, %struct.udev_device* %1, i32 %2) {
%4 = icmp ne i32 %2, 0
%5 = icmp ne %struct.udev_device* %1, null
%6 = and i1 %5, %4
br i1 %6, label %7, label %28
7: ; preds = %3
%8 = tail call %struct.udev_list_entry* @udev_device_get_tags_list_entry(%struct.udev_device* %1)
%9 = icmp eq %struct.udev_list_entry* %8, null
br i1 %9, label %28, label %10
10: ; preds = %7, %25
%11 = phi %struct.udev_list_entry* [ %26, %25 ], [ %8, %7 ]
%12 = tail call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %11)
%13 = tail call %struct.udev_list_entry* @udev_device_get_tags_list_entry(%struct.udev_device* %0)
%14 = icmp eq %struct.udev_list_entry* %13, null
br i1 %14, label %23, label %15
15: ; preds = %10, %20
%16 = phi %struct.udev_list_entry* [ %21, %20 ], [ %13, %10 ]
%17 = tail call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %16)
%18 = tail call i64 @strcmp(i8* %17, i8* %12)
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %16)
%22 = icmp eq %struct.udev_list_entry* %21, null
br i1 %22, label %23, label %15
23: ; preds = %20, %10
%24 = tail call i32 @udev_device_tag(%struct.udev_device* %1, i8* %12, i32 0)
br label %25
25: ; preds = %15, %23
%26 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %11)
%27 = icmp eq %struct.udev_list_entry* %26, null
br i1 %27, label %28, label %10
28: ; preds = %25, %7, %3
%29 = tail call %struct.udev_list_entry* @udev_device_get_tags_list_entry(%struct.udev_device* %0)
%30 = icmp eq %struct.udev_list_entry* %29, null
br i1 %30, label %37, label %31
31: ; preds = %28, %31
%32 = phi %struct.udev_list_entry* [ %35, %31 ], [ %29, %28 ]
%33 = tail call i8* @udev_list_entry_get_name(%struct.udev_list_entry* %32)
%34 = tail call i32 @udev_device_tag(%struct.udev_device* %0, i8* %33, i32 %2)
%35 = tail call %struct.udev_list_entry* @udev_list_entry_get_next(%struct.udev_list_entry* %32)
%36 = icmp eq %struct.udev_list_entry* %35, null
br i1 %36, label %37, label %31
37: ; preds = %31, %28
ret i32 0
}