#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 */
struct katcp_sensor *create_sensor_katcp(struct katcp_dispatch *, char *,
                                         char *, char *, int, int, int,
                                         int /*<<< orphan*/ *);
scalar_t__ create_sensor_vector_discrete_katcp(struct katcp_dispatch *,
                                               struct katcp_sensor *, char **,
                                               unsigned int);
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_discrete_acquire_katcp(
    struct katcp_dispatch *,
    int (*)(struct katcp_dispatch *, struct katcp_acquire *), void *,
    void (*)(struct katcp_dispatch *, struct katcp_acquire *));
int register_discrete_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),
    char **vector, unsigned int size) {
  struct katcp_sensor *sn;
  struct katcp_acquire *a;
  sn = create_sensor_katcp(d, name, description, units, 2, 2, mode, NULL);
  if (sn == NULL) {
    return -1;
  }
  if (create_sensor_vector_discrete_katcp(d, sn, vector, size) < 0) {
    destroy_sensor_katcp(d, sn);
    return -1;
  }
  a = setup_discrete_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_discrete_sensor_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
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,%r9d
xor    %r8d,%r8d
mov    %r9d,%r8d
mov    %eax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1030 <create_sensor_katcp@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11d9 <register_discrete_sensor_katcp+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <register_discrete_sensor_katcp+0x139>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x20(%rbp),%rdx
mov    0x28(%rbp),%ecx
call   1040 <create_sensor_vector_discrete_katcp@plt>
cmp    $0x0,%rax
jge    1210 <register_discrete_sensor_katcp+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <destroy_sensor_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <register_discrete_sensor_katcp+0x139>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1050 <setup_discrete_acquire_katcp@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    124d <register_discrete_sensor_katcp+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <destroy_sensor_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <register_discrete_sensor_katcp+0x139>
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     1292 <register_discrete_sensor_katcp+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <destroy_sensor_katcp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1080 <destroy_acquire_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <register_discrete_sensor_katcp+0x139>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_discrete_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    $0x2,%r9d
push   $0x0
push   %rax
call   1030 <create_sensor_katcp@plt>
add    $0x10,%rsp
mov    $0xffffffff,%ebx
test   %rax,%rax
je     1213 <register_discrete_sensor_katcp+0xb3>
mov    %rax,%r12
mov    0x48(%rsp),%ecx
mov    0x40(%rsp),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <create_sensor_vector_discrete_katcp@plt>
test   %rax,%rax
js     1203 <register_discrete_sensor_katcp+0xa3>
mov    0x38(%rsp),%rcx
mov    0x30(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <setup_discrete_acquire_katcp@plt>
test   %rax,%rax
je     1203 <register_discrete_sensor_katcp+0xa3>
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     1213 <register_discrete_sensor_katcp+0xb3>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <destroy_sensor_katcp@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <destroy_acquire_katcp@plt>
jmp    120e <register_discrete_sensor_katcp+0xae>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <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_discrete_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, i8** %8, i32 %9) {
%11 = alloca i32
%12 = alloca %struct.katcp_dispatch*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)*
%18 = alloca i8*
%19 = alloca void (%struct.katcp_dispatch*, %struct.katcp_acquire*)*
%20 = alloca i8**
%21 = alloca i32
%22 = alloca %struct.katcp_sensor*
%23 = alloca %struct.katcp_acquire*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %12
store i32 %1, i32* %13
store i8* %2, i8** %14
store i8* %3, i8** %15
store i8* %4, i8** %16
store i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %5, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %17
store i8* %6, i8** %18
store void (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %7, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %19
store i8** %8, i8*** %20
store i32 %9, i32* %21
%24 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%25 = load i8*, i8** %14
%26 = load i8*, i8** %15
%27 = load i8*, i8** %16
%28 = load i32, i32* %13
%29 = call %struct.katcp_sensor* @create_sensor_katcp(%struct.katcp_dispatch* %24, i8* %25, i8* %26, i8* %27, i32 2, i32 2, i32 %28, i32* null)
store %struct.katcp_sensor* %29, %struct.katcp_sensor** %22
%30 = load %struct.katcp_sensor*, %struct.katcp_sensor** %22
%31 = icmp eq %struct.katcp_sensor* %30, null
br i1 %31, label %32, label %33
32: ; preds = %10
store i32 -1, i32* %11
br label %70
33: ; preds = %10
%34 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%35 = load %struct.katcp_sensor*, %struct.katcp_sensor** %22
%36 = load i8**, i8*** %20
%37 = load i32, i32* %21
%38 = call i64 @create_sensor_vector_discrete_katcp(%struct.katcp_dispatch* %34, %struct.katcp_sensor* %35, i8** %36, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%42 = load %struct.katcp_sensor*, %struct.katcp_sensor** %22
%43 = call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %41, %struct.katcp_sensor* %42)
store i32 -1, i32* %11
br label %70
44: ; preds = %33
%45 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%46 = load i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)*, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %17
%47 = load i8*, i8** %18
%48 = load void (%struct.katcp_dispatch*, %struct.katcp_acquire*)*, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %19
%49 = call %struct.katcp_acquire* @setup_discrete_acquire_katcp(%struct.katcp_dispatch* %45, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %46, i8* %47, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %48)
store %struct.katcp_acquire* %49, %struct.katcp_acquire** %23
%50 = load %struct.katcp_acquire*, %struct.katcp_acquire** %23
%51 = icmp eq %struct.katcp_acquire* %50, null
br i1 %51, label %52, label %56
52: ; preds = %44
%53 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%54 = load %struct.katcp_sensor*, %struct.katcp_sensor** %22
%55 = call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %53, %struct.katcp_sensor* %54)
store i32 -1, i32* %11
br label %70
56: ; preds = %44
%57 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%58 = load %struct.katcp_acquire*, %struct.katcp_acquire** %23
%59 = load %struct.katcp_sensor*, %struct.katcp_sensor** %22
%60 = call i64 @link_acquire_katcp(%struct.katcp_dispatch* %57, %struct.katcp_acquire* %58, %struct.katcp_sensor* %59, i32* null)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %69
62: ; preds = %56
%63 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%64 = load %struct.katcp_sensor*, %struct.katcp_sensor** %22
%65 = call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %63, %struct.katcp_sensor* %64)
%66 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %12
%67 = load %struct.katcp_acquire*, %struct.katcp_acquire** %23
%68 = call i32 @destroy_acquire_katcp(%struct.katcp_dispatch* %66, %struct.katcp_acquire* %67)
store i32 -1, i32* %11
br label %70
69: ; preds = %56
store i32 0, i32* %11
br label %70
70: ; preds = %69, %62, %52, %40, %32
%71 = load i32, i32* %11
ret i32 %71
}

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