#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 dtree_dev_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dtree_dev_free(struct dtree_dev_t *);
struct dtree_dev_t *dtree_next();
scalar_t__ is_compatible(struct dtree_dev_t *, char const *);
scalar_t__ strlen(char const *);
struct dtree_dev_t *dtree_bycompat(const char *compat) {
  struct dtree_dev_t *curr = NULL;
  if (compat == NULL || strlen(compat) == 0)
    return NULL;
  while ((curr = dtree_next()) != NULL) {
    if (is_compatible(curr, compat))
      break;
    dtree_dev_free(curr);
  }
  return curr;
}


x86 assembly (clang, -O0):
<dtree_bycompat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1172 <dtree_bycompat+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    117f <dtree_bycompat+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11cb <dtree_bycompat+0x8b>
jmp    1184 <dtree_bycompat+0x44>
mov    $0x0,%al
call   1040 <dtree_next@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c3 <dtree_bycompat+0x83>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <is_compatible@plt>
cmp    $0x0,%rax
je     11b5 <dtree_bycompat+0x75>
jmp    11c3 <dtree_bycompat+0x83>
mov    -0x18(%rbp),%rdi
call   1060 <dtree_dev_free@plt>
jmp    1184 <dtree_bycompat+0x44>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtree_bycompat>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1187 <dtree_bycompat+0x57>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     1187 <dtree_bycompat+0x57>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <dtree_next@plt>
test   %rax,%rax
je     1189 <dtree_bycompat+0x59>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <is_compatible@plt>
test   %rax,%rax
jne    1189 <dtree_bycompat+0x59>
mov    %rbx,%rdi
call   1050 <dtree_dev_free@plt>
xor    %eax,%eax
call   1030 <dtree_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <dtree_bycompat+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dtree_dev_t = type { i32 }
define %struct.dtree_dev_t* @dtree_bycompat(i8* %0) {
%2 = alloca %struct.dtree_dev_t*
%3 = alloca i8*
%4 = alloca %struct.dtree_dev_t*
store i8* %0, i8** %3
store %struct.dtree_dev_t* null, %struct.dtree_dev_t** %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7, %1
store %struct.dtree_dev_t* null, %struct.dtree_dev_t** %2
br label %27
12: ; preds = %7
br label %13
13: ; preds = %22, %12
%14 = call %struct.dtree_dev_t* (...) @dtree_next()
store %struct.dtree_dev_t* %14, %struct.dtree_dev_t** %4
%15 = icmp ne %struct.dtree_dev_t* %14, null
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %4
%18 = load i8*, i8** %3
%19 = call i64 @is_compatible(%struct.dtree_dev_t* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
br label %25
22: ; preds = %16
%23 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %4
%24 = call i32 @dtree_dev_free(%struct.dtree_dev_t* %23)
br label %13
25: ; preds = %21, %13
%26 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %4
store %struct.dtree_dev_t* %26, %struct.dtree_dev_t** %2
br label %27
27: ; preds = %25, %11
%28 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %2
ret %struct.dtree_dev_t* %28
}

LLVM IR (-O2):
%struct.dtree_dev_t = type { i32 }
define %struct.dtree_dev_t* @dtree_bycompat(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call %struct.dtree_dev_t* (...) @dtree_next()
%8 = icmp eq %struct.dtree_dev_t* %7, null
br i1 %8, label %17, label %9
9: ; preds = %6, %13
%10 = phi %struct.dtree_dev_t* [ %15, %13 ], [ %7, %6 ]
%11 = tail call i64 @is_compatible(%struct.dtree_dev_t* %10, i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = tail call i32 @dtree_dev_free(%struct.dtree_dev_t* %10)
%15 = tail call %struct.dtree_dev_t* (...) @dtree_next()
%16 = icmp eq %struct.dtree_dev_t* %15, null
br i1 %16, label %17, label %9
17: ; preds = %9, %13, %6, %1, %3
%18 = phi %struct.dtree_dev_t* [ null, %3 ], [ null, %1 ], [ null, %6 ], [ %10, %9 ], [ null, %13 ]
ret %struct.dtree_dev_t* %18
}