#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_integer_katcp(struct katcp_dispatch *,
                                       struct katcp_sensor *, int, int, int,
                                       int);
struct katcp_sensor *
create_sensor_katcp(struct katcp_dispatch *, char *, char *, char *, int,
                    int /*<<< orphan*/, int,
                    int (*)(struct katcp_dispatch *, struct katcp_sensor *));
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_integer_acquire_katcp(
    struct katcp_dispatch *,
    int (*)(struct katcp_dispatch *, struct katcp_acquire *), void *,
    void (*)(struct katcp_dispatch *, struct katcp_acquire *));
int declare_integer_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),
    int nom_min, int nom_max, int warn_min, int warn_max,
    int (*flush)(struct katcp_dispatch *d, struct katcp_sensor *sn)) {
  struct katcp_sensor *sn;
  struct katcp_acquire *a;
  sn = create_sensor_katcp(d, name, description, units, 2, 0, mode, flush);
  if (sn == NULL) {
    return -1;
  }
  if (create_sensor_integer_katcp(d, sn, nom_min, nom_max, warn_min, warn_max) <
      0) {
    destroy_sensor_katcp(d, sn);
    return -1;
  }
  a = setup_integer_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):
<declare_integer_sensor_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%eax
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
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),%r10d
mov    0x40(%rbp),%rax
mov    $0x2,%r8d
xor    %r9d,%r9d
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <create_sensor_katcp@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11e1 <declare_integer_sensor_katcp+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <declare_integer_sensor_katcp+0x148>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x20(%rbp),%edx
mov    0x28(%rbp),%ecx
mov    0x30(%rbp),%r8d
mov    0x38(%rbp),%r9d
call   1050 <create_sensor_integer_katcp@plt>
cmp    $0x0,%rax
jge    121f <declare_integer_sensor_katcp+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <destroy_sensor_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <declare_integer_sensor_katcp+0x148>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1040 <setup_integer_acquire_katcp@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    125c <declare_integer_sensor_katcp+0xfc>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <destroy_sensor_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <declare_integer_sensor_katcp+0x148>
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     12a1 <declare_integer_sensor_katcp+0x141>
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    12a8 <declare_integer_sensor_katcp+0x148>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<declare_integer_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
xor    %r9d,%r9d
push   0x60(%rsp)
push   %rax
call   1030 <create_sensor_katcp@plt>
add    $0x10,%rsp
mov    $0xffffffff,%ebx
test   %rax,%rax
je     121f <declare_integer_sensor_katcp+0xbf>
mov    %rax,%r12
mov    0x58(%rsp),%r9d
mov    0x50(%rsp),%r8d
mov    0x48(%rsp),%ecx
mov    0x40(%rsp),%edx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <create_sensor_integer_katcp@plt>
test   %rax,%rax
js     120f <declare_integer_sensor_katcp+0xaf>
mov    0x38(%rsp),%rcx
mov    0x30(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <setup_integer_acquire_katcp@plt>
test   %rax,%rax
je     120f <declare_integer_sensor_katcp+0xaf>
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     121f <declare_integer_sensor_katcp+0xbf>
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    121a <declare_integer_sensor_katcp+0xba>
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 @declare_integer_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, i32 %8, i32 %9, i32 %10, i32 %11, i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)* %12) {
%14 = alloca i32
%15 = alloca %struct.katcp_dispatch*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)*
%21 = alloca i8*
%22 = alloca void (%struct.katcp_dispatch*, %struct.katcp_acquire*)*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)*
%28 = alloca %struct.katcp_sensor*
%29 = alloca %struct.katcp_acquire*
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %15
store i32 %1, i32* %16
store i8* %2, i8** %17
store i8* %3, i8** %18
store i8* %4, i8** %19
store i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %5, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %20
store i8* %6, i8** %21
store void (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %7, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %22
store i32 %8, i32* %23
store i32 %9, i32* %24
store i32 %10, i32* %25
store i32 %11, i32* %26
store i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)* %12, i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)** %27
%30 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%31 = load i8*, i8** %17
%32 = load i8*, i8** %18
%33 = load i8*, i8** %19
%34 = load i32, i32* %16
%35 = load i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)*, i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)** %27
%36 = call %struct.katcp_sensor* @create_sensor_katcp(%struct.katcp_dispatch* %30, i8* %31, i8* %32, i8* %33, i32 2, i32 0, i32 %34, i32 (%struct.katcp_dispatch*, %struct.katcp_sensor*)* %35)
store %struct.katcp_sensor* %36, %struct.katcp_sensor** %28
%37 = load %struct.katcp_sensor*, %struct.katcp_sensor** %28
%38 = icmp eq %struct.katcp_sensor* %37, null
br i1 %38, label %39, label %40
39: ; preds = %13
store i32 -1, i32* %14
br label %79
40: ; preds = %13
%41 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%42 = load %struct.katcp_sensor*, %struct.katcp_sensor** %28
%43 = load i32, i32* %23
%44 = load i32, i32* %24
%45 = load i32, i32* %25
%46 = load i32, i32* %26
%47 = call i64 @create_sensor_integer_katcp(%struct.katcp_dispatch* %41, %struct.katcp_sensor* %42, i32 %43, i32 %44, i32 %45, i32 %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %40
%50 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%51 = load %struct.katcp_sensor*, %struct.katcp_sensor** %28
%52 = call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %50, %struct.katcp_sensor* %51)
store i32 -1, i32* %14
br label %79
53: ; preds = %40
%54 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%55 = load i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)*, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %20
%56 = load i8*, i8** %21
%57 = load void (%struct.katcp_dispatch*, %struct.katcp_acquire*)*, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)** %22
%58 = call %struct.katcp_acquire* @setup_integer_acquire_katcp(%struct.katcp_dispatch* %54, i32 (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %55, i8* %56, void (%struct.katcp_dispatch*, %struct.katcp_acquire*)* %57)
store %struct.katcp_acquire* %58, %struct.katcp_acquire** %29
%59 = load %struct.katcp_acquire*, %struct.katcp_acquire** %29
%60 = icmp eq %struct.katcp_acquire* %59, null
br i1 %60, label %61, label %65
61: ; preds = %53
%62 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%63 = load %struct.katcp_sensor*, %struct.katcp_sensor** %28
%64 = call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %62, %struct.katcp_sensor* %63)
store i32 -1, i32* %14
br label %79
65: ; preds = %53
%66 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%67 = load %struct.katcp_acquire*, %struct.katcp_acquire** %29
%68 = load %struct.katcp_sensor*, %struct.katcp_sensor** %28
%69 = call i64 @link_acquire_katcp(%struct.katcp_dispatch* %66, %struct.katcp_acquire* %67, %struct.katcp_sensor* %68, i32* null)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %65
%72 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%73 = load %struct.katcp_sensor*, %struct.katcp_sensor** %28
%74 = call i32 @destroy_sensor_katcp(%struct.katcp_dispatch* %72, %struct.katcp_sensor* %73)
%75 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %15
%76 = load %struct.katcp_acquire*, %struct.katcp_acquire** %29
%77 = call i32 @destroy_acquire_katcp(%struct.katcp_dispatch* %75, %struct.katcp_acquire* %76)
store i32 -1, i32* %14
br label %79
78: ; preds = %65
store i32 0, i32* %14
br label %79
79: ; preds = %78, %71, %61, %49, %39
%80 = load i32, i32* %14
ret i32 %80
}

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