#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 iio_device {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int add_attr_to_device(struct iio_device *, char const *);
int add_channel(struct iio_device *, char const *, char const *, int);
int /*<<< orphan*/ is_channel(char const *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strrchr(char const *, char);
int add_attr_or_channel_helper(struct iio_device *dev, const char *path,
                               bool dir_is_scan_elements) {
  char buf[1024];
  const char *name = strrchr(path, '/') + 1;
  if (dir_is_scan_elements) {
    snprintf(buf, sizeof(buf), "scan_elements/%s", name);
    path = buf;
  } else {
    if (!is_channel(name, true))
      return add_attr_to_device(dev, name);
    path = name;
  }
  return add_channel(dev, name, path, dir_is_scan_elements);
}


x86 assembly (clang, -O0):
<add_attr_or_channel_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x428(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11b8 <add_attr_or_channel_helper+0x68>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rcx
mov    $0x400,%esi
lea    0xe5d(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11f5 <add_attr_or_channel_helper+0xa5>
mov    -0x428(%rbp),%rdi
mov    $0x1,%esi
call   1030 <is_channel@plt>
cmp    $0x0,%eax
jne    11ea <add_attr_or_channel_helper+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1060 <add_attr_to_device@plt>
mov    %eax,-0x4(%rbp)
jmp    120f <add_attr_or_channel_helper+0xbf>
mov    -0x428(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1070 <add_channel@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_attr_or_channel_helper>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edx,%r15d
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
add    $0x1,%rbx
test   %r15d,%r15d
je     1198 <add_attr_or_channel_helper+0x48>
mov    %rsp,%rbp
lea    0xe7a(%rip),%rdx
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
jmp    11ac <add_attr_or_channel_helper+0x5c>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <is_channel@plt>
mov    %rbx,%rbp
test   %eax,%eax
je     11cb <add_attr_or_channel_helper+0x7b>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
call   1070 <add_channel@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <add_attr_to_device@plt>

LLVM IR (-O0):
%struct.iio_device = type { i32 }
@.str = [17 x i8] c"scan_elements/%s\00"
define i32 @add_attr_or_channel_helper(%struct.iio_device* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.iio_device*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i8*
store %struct.iio_device* %0, %struct.iio_device** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8* %12, i8** %9
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = load i8*, i8** %9
%18 = call i32 @snprintf(i8* %16, i32 1024, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8* %19, i8** %6
br label %30
20: ; preds = %3
%21 = load i8*, i8** %9
%22 = call i32 @is_channel(i8* %21, i32 1)
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load %struct.iio_device*, %struct.iio_device** %5
%26 = load i8*, i8** %9
%27 = call i32 @add_attr_to_device(%struct.iio_device* %25, i8* %26)
store i32 %27, i32* %4
br label %36
28: ; preds = %20
%29 = load i8*, i8** %9
store i8* %29, i8** %6
br label %30
30: ; preds = %28, %15
%31 = load %struct.iio_device*, %struct.iio_device** %5
%32 = load i8*, i8** %9
%33 = load i8*, i8** %6
%34 = load i32, i32* %7
%35 = call i32 @add_channel(%struct.iio_device* %31, i8* %32, i8* %33, i32 %34)
store i32 %35, i32* %4
br label %36
36: ; preds = %30, %24
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.iio_device = type { i32 }
@.str = [17 x i8] c"scan_elements/%s\00"
define i32 @add_attr_or_channel_helper(%struct.iio_device* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = icmp eq i32 %2, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %16
11: ; preds = %3
%12 = tail call i32 @is_channel(i8* %7, i32 1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @add_attr_to_device(%struct.iio_device* %0, i8* %7)
br label %19
16: ; preds = %11, %9
%17 = phi i8* [ %5, %9 ], [ %7, %11 ]
%18 = call i32 @add_channel(%struct.iio_device* %0, i8* %7, i8* %17, i32 %2)
br label %19
19: ; preds = %16, %14
%20 = phi i32 [ %18, %16 ], [ %15, %14 ]
ret i32 %20
}