#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*/ ploop_free_array(char **);
int ploop_get_dev_by_delta(char const *, int /*<<< orphan*/ *, char const *,
                           char ***);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int ploop_find_dev(const char *component_name, const char *delta, char *out,
                   int size) {
  int ret;
  char **devs;
  ret = ploop_get_dev_by_delta(delta, NULL,
                               component_name ? component_name : "", &devs);
  if (ret == 0)
    snprintf(out, size, "%s", devs[0]);
  ploop_free_array(devs);
  return ret;
}


x86 assembly (clang, -O0):
<ploop_find_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1167 <ploop_find_dev+0x37>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1177 <ploop_find_dev+0x47>
lea    0xe94(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1177 <ploop_find_dev+0x47>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rcx
call   1050 <ploop_get_dev_by_delta@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11b3 <ploop_find_dev+0x83>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
lea    0xe52(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <ploop_free_array@plt>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ploop_find_dev>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
test   %rdi,%rdi
lea    0xeba(%rip),%rdx
cmovne %rdi,%rdx
lea    0x8(%rsp),%rcx
mov    %rsi,%rdi
xor    %esi,%esi
call   1050 <ploop_get_dev_by_delta@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    117b <ploop_find_dev+0x4b>
mov    0x8(%rsp),%rax
mov    (%rax),%rcx
lea    0xe90(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <snprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <ploop_free_array@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i32 @ploop_find_dev(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %6
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load i8*, i8** %5
br label %17
16: ; preds = %4
br label %17
17: ; preds = %16, %14
%18 = phi i8* [ %15, %14 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %16 ]
%19 = call i32 @ploop_get_dev_by_delta(i8* %11, i32* null, i8* %18, i8*** %10)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = load i8**, i8*** %10
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @snprintf(i8* %23, i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %22, %17
%30 = load i8**, i8*** %10
%31 = call i32 @ploop_free_array(i8** %30)
%32 = load i32, i32* %9
ret i32 %32
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i32 @ploop_find_dev(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8**
%6 = bitcast i8*** %5 to i8*
%7 = icmp eq i8* %0, null
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%9 = call i32 @ploop_get_dev_by_delta(i8* %1, i32* null, i8* %8, i8*** %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = call i32 @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %4
%16 = load i8**, i8*** %5
%17 = call i32 @ploop_free_array(i8** %16)
ret i32 %9
}