#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 katcp_sensor {
  int dummy;
};
struct katcp_dispatch {
  int dummy;
};
struct katcp_acquire {
  int dummy;
};

/* Variables and functions */
scalar_t__ create_sensor_boolean_katcp(struct katcp_dispatch *,
                                       struct katcp_sensor *);
struct katcp_sensor *create_sensor_katcp(struct katcp_dispatch *, char *,
                                         char *, char *, int, int, int,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ destroy_acquire_katcp(struct katcp_dispatch *,
                                         struct katcp_acquire *);
int /*<<< orphan*/ destroy_sensor_katcp(struct katcp_dispatch *,
                                        struct katcp_sensor *);
scalar_t__ link_acquire_katcp(struct katcp_dispatch *, struct katcp_acquire *,
                              struct katcp_sensor *, int /*<<< orphan*/ *);
struct katcp_acquire *setup_boolean_acquire_katcp(
    struct katcp_dispatch *,
    int (*)(struct katcp_dispatch *, struct katcp_acquire *), void *,
    void (*)(struct katcp_dispatch *, struct katcp_acquire *));
int register_boolean_sensor_katcp(
    struct katcp_dispatch *d, int mode, char *name, char *description,
    char *units, int (*get)(struct katcp_dispatch *d, struct katcp_acquire *a),
    void *local,
    void (*release)(struct katcp_dispatch *d, struct katcp_acquire *a)) {
  struct katcp_sensor *sn;
  struct katcp_acquire *a;
  sn = create_sensor_katcp(d, name, description, units, 2, 1, mode, NULL);
  if (sn == NULL) {
    return -1;
  }
  if (create_sensor_boolean_katcp(d, sn) < 0) {
    destroy_sensor_katcp(d, sn);
    return -1;
  }
  a = setup_boolean_acquire_katcp(d, get, local, release);
  if (a == NULL) {
    destroy_sensor_katcp(d, sn);
    return -1;
  }
  if (link_acquire_katcp(d, a, sn, NULL)) {
    destroy_sensor_katcp(d, sn);
    destroy_acquire_katcp(d, a);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<register_boolean_sensor_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x14(%rbp),%eax
mov    $0x2,%r8d
mov    $0x1,%r9d
xor    %r10d,%r10d
mov    %eax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1030 <create_sensor_katcp@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11d5 <register_boolean_sensor_katcp+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <register_boolean_sensor_katcp+0x12e>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <create_sensor_boolean_katcp@plt>
cmp    $0x0,%rax
jge    1205 <register_boolean_sensor_katcp+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <destroy_sensor_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <register_boolean_sensor_katcp+0x12e>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1040 <setup_boolean_acquire_katcp@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1242 <register_boolean_sensor_katcp+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <destroy_sensor_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <register_boolean_sensor_katcp+0x12e>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <link_acquire_katcp@plt>
cmp    $0x0,%rax
je     1287 <register_boolean_sensor_katcp+0x127>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <destroy_sensor_katcp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1080 <destroy_acquire_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <register_boolean_sensor_katcp+0x12e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_boolean_sensor_katcp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %esi,%eax
mov    %rdi,%r14
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    $0x2,%r8d
mov    $0x1,%r9d
push   $0x0
push   %rax
call   1030 <create_sensor_katcp@plt>
add    $0x10,%rsp
mov    $0xffffffff,%ebx
test   %rax,%rax
je     120a <register_boolean_sensor_katcp+0xaa>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <create_sensor_boolean_katcp@plt>
test   %rax,%rax
js     11fa <register_boolean_sensor_katcp+0x9a>
mov    0x38(%rsp),%rcx
mov    0x30(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <setup_boolean_acquire_katcp@plt>
test   %rax,%rax
je     11fa <register_boolean_sensor_katcp+0x9a>
mov    %rax,%r15
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1070 <link_acquire_katcp@plt>
test   %rax,%rax
je     120a <register_boolean_sensor_katcp+0xaa>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <destroy_sensor_katcp@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <destroy_acquire_katcp@plt>
jmp    1205 <register_boolean_sensor_katcp+0xa5>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <destroy_sensor_katcp@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_acquire = type { i32 }
%struct.katcp_sensor = type { i32 }
define i32 @register_boolean_sensor_katcp(%struct.katcp_dispatch* %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %5, i8* %6, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %7) {
%9 = tail call %struct.katcp_sensor* @create_sensor_katcp(%struct.katcp_dispatch* %0, i8* %2, i8* %3, i8* %4, i32 2, i32 1, i32 %1, i32* null)
%10 = icmp eq %struct.katcp_sensor* %9, null
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = tail call i64 @create_sensor_boolean_katcp(%struct.katcp_dispatch* %0, %struct.katcp_sensor* %9)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %0, %struct.katcp_sensor* %9)
br label %27
16: ; preds = %11
%17 = tail call %struct.katcp_acquire* @setup_boolean_acquire_katcp(%struct.katcp_dispatch* %0, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %5, i8* %6, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %7)
%18 = icmp eq %struct.katcp_acquire* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %0, %struct.katcp_sensor* %9)
br label %27
21: ; preds = %16
%22 = tail call i64 @link_acquire_katcp(%struct.katcp_dispatch* %0, %struct.katcp_acquire* %17, %struct.katcp_sensor* %9, i32* null)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = tail call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %0, %struct.katcp_sensor* %9)
%26 = tail call i32 @destroy_acquire_katcp(%struct.katcp_dispatch* %0, %struct.katcp_acquire* %17)
br label %27
27: ; preds = %21, %8, %24, %19, %14
%28 = phi i32 [ -1, %14 ], [ -1, %19 ], [ -1, %24 ], [ -1, %8 ], [ 0, %21 ]
ret i32 %28
}