#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;
};

/* Variables and functions */
char *arg_string_katcp(struct katcp_dispatch *, int);
scalar_t__ configure_sensor_katcp(struct katcp_dispatch *,
                                  struct katcp_sensor *, int, int, char *);
int extra_response_katcp(struct katcp_dispatch *, int, char *);
struct katcp_sensor *find_sensor_katcp(struct katcp_dispatch *, char *);
int /*<<< orphan*/ log_message_katcp(struct katcp_dispatch *, int,
                                     int /*<<< orphan*/ *, char *, char *, ...);
scalar_t__ reply_sensor_sampling_katcp(struct katcp_dispatch *,
                                       struct katcp_sensor *);
int strategy_code_sensor_katcp(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int sensor_sampling_cmd_katcp(struct katcp_dispatch *d, int argc) {
  struct katcp_sensor *sn;
  char *name, *strategy, *extra;
  int value, manual;
  if (argc <= 1) {
    return extra_response_katcp(d, (-2), "usage");
  }
  name = arg_string_katcp(d, 1);
  if (name == NULL) {
    return (-1);
  }
  strategy = NULL;
  extra = NULL;
  manual = 1;
  if (argc > 2) {
    strategy = arg_string_katcp(d, 2);
    if (argc > 3) {
      extra = arg_string_katcp(d, 3);
    }
  }
  sn = find_sensor_katcp(d, name);
  if (sn == NULL) {
    log_message_katcp(d, 4, NULL, "unknown sensor %s", name);
    return (-1);
  }
  if (strategy) {
    if (!strcmp(strategy, "auto")) {
      manual = 0;
      value = (-1);
    } else {
      manual = 1;
      value = strategy_code_sensor_katcp(strategy);
      if (value < 0) {
        log_message_katcp(d, 4, NULL, "unknown strategy %s", strategy);
        return (-1);
      }
    }
    if (configure_sensor_katcp(d, sn, value, manual, extra) < 0) {
      log_message_katcp(d, 4, NULL,
                        "unable to configure sensor %s for strategy %s", name,
                        strategy);
      return (-1);
    }
  }
  if (reply_sensor_sampling_katcp(d, sn) < 0) {
    return (-1);
  }
  return 1;
}


x86 assembly (clang, -O0):
<sensor_sampling_cmd_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     11b6 <sensor_sampling_cmd_katcp+0x36>
mov    -0x10(%rbp),%rdi
mov    $0xfffffffe,%esi
lea    0xe57(%rip),%rdx
call   1080 <extra_response_katcp@plt>
mov    %eax,-0x4(%rbp)
jmp    137d <sensor_sampling_cmd_katcp+0x1fd>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <arg_string_katcp@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11df <sensor_sampling_cmd_katcp+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <sensor_sampling_cmd_katcp+0x1fd>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x40(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    1233 <sensor_sampling_cmd_katcp+0xb3>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1060 <arg_string_katcp@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x14(%rbp)
jle    122e <sensor_sampling_cmd_katcp+0xae>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
call   1060 <arg_string_katcp@plt>
mov    %rax,-0x38(%rbp)
jmp    1233 <sensor_sampling_cmd_katcp+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <find_sensor_katcp@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127a <sensor_sampling_cmd_katcp+0xfa>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%r8
mov    $0x4,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd9f(%rip),%rcx
mov    $0x0,%al
call   10a0 <log_message_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <sensor_sampling_cmd_katcp+0x1fd>
cmpq   $0x0,-0x30(%rbp)
je     1353 <sensor_sampling_cmd_katcp+0x1d3>
mov    -0x30(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12b1 <sensor_sampling_cmd_katcp+0x131>
movl   $0x0,-0x40(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
jmp    12fe <sensor_sampling_cmd_katcp+0x17e>
movl   $0x1,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strategy_code_sensor_katcp@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    12f9 <sensor_sampling_cmd_katcp+0x179>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%r8
mov    $0x4,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd37(%rip),%rcx
mov    $0x0,%al
call   10a0 <log_message_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <sensor_sampling_cmd_katcp+0x1fd>
jmp    12fe <sensor_sampling_cmd_katcp+0x17e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%r8
call   1030 <configure_sensor_katcp@plt>
cmp    $0x0,%rax
jge    134e <sensor_sampling_cmd_katcp+0x1ce>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    $0x4,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    0xcf6(%rip),%rcx
mov    $0x0,%al
call   10a0 <log_message_katcp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <sensor_sampling_cmd_katcp+0x1fd>
jmp    1353 <sensor_sampling_cmd_katcp+0x1d3>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <reply_sensor_sampling_katcp@plt>
cmp    $0x0,%rax
jge    1376 <sensor_sampling_cmd_katcp+0x1f6>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <sensor_sampling_cmd_katcp+0x1fd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sensor_sampling_cmd_katcp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x1,%esi
jg     11b5 <sensor_sampling_cmd_katcp+0x35>
lea    0xe66(%rip),%rdx
mov    %rbx,%rdi
mov    $0xfffffffe,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <extra_response_katcp@plt>
mov    %esi,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <arg_string_katcp@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
je     12b0 <sensor_sampling_cmd_katcp+0x130>
mov    %rax,%r14
mov    %rbx,%rdi
cmp    $0x3,%ebp
jb     11f4 <sensor_sampling_cmd_katcp+0x74>
mov    $0x2,%esi
call   1060 <arg_string_katcp@plt>
mov    %rax,%r15
cmp    $0x3,%ebp
jne    120a <sensor_sampling_cmd_katcp+0x8a>
xor    %ebp,%ebp
jmp    121a <sensor_sampling_cmd_katcp+0x9a>
mov    %r14,%rsi
call   1090 <find_sensor_katcp@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1295 <sensor_sampling_cmd_katcp+0x115>
jmp    125e <sensor_sampling_cmd_katcp+0xde>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <arg_string_katcp@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <find_sensor_katcp@plt>
test   %rax,%rax
je     125e <sensor_sampling_cmd_katcp+0xde>
mov    %rax,%r12
test   %r15,%r15
je     1295 <sensor_sampling_cmd_katcp+0x115>
lea    0xddf(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     127b <sensor_sampling_cmd_katcp+0xfb>
mov    %r15,%rdi
call   1070 <strategy_code_sensor_katcp@plt>
test   %eax,%eax
js     12e8 <sensor_sampling_cmd_katcp+0x168>
mov    %eax,%edx
mov    $0x1,%ecx
jmp    1282 <sensor_sampling_cmd_katcp+0x102>
lea    0xda1(%rip),%rcx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
mov    %r14,%r8
xor    %eax,%eax
call   10a0 <log_message_katcp@plt>
jmp    12b0 <sensor_sampling_cmd_katcp+0x130>
xor    %ecx,%ecx
mov    $0xffffffff,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%r8
call   1030 <configure_sensor_katcp@plt>
test   %rax,%rax
js     12c2 <sensor_sampling_cmd_katcp+0x142>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <reply_sensor_sampling_katcp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setns  %cl
lea    (%rcx,%rcx,1),%r13d
add    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd68(%rip),%rcx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
mov    %r14,%r8
mov    %r15,%r9
xor    %eax,%eax
call   10a0 <log_message_katcp@plt>
mov    $0xffffffff,%r13d
jmp    12b0 <sensor_sampling_cmd_katcp+0x130>
lea    0xd2e(%rip),%rcx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
mov    %r15,%r8
xor    %eax,%eax
call   10a0 <log_message_katcp@plt>
mov    $0xffffffff,%r13d
jmp    12b0 <sensor_sampling_cmd_katcp+0x130>

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_sensor = type { i32 }
@.str = [6 x i8] c"usage\00"
@.str.1 = [18 x i8] c"unknown sensor %s\00"
@.str.2 = [5 x i8] c"auto\00"
@.str.3 = [20 x i8] c"unknown strategy %s\00"
@.str.4 = [46 x i8] c"unable to configure sensor %s for strategy %s\00"
define i32 @sensor_sampling_cmd_katcp(%struct.katcp_dispatch* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.katcp_dispatch*
%5 = alloca i32
%6 = alloca %struct.katcp_sensor*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %4
store i32 %1, i32* %5
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%16 = call i32 @extra_response_katcp(%struct.katcp_dispatch* %15, i32 -2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %3
br label %84
17: ; preds = %2
%18 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%19 = call i8* @arg_string_katcp(%struct.katcp_dispatch* %18, i32 1)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %3
br label %84
23: ; preds = %17
store i8* null, i8** %8
store i8* null, i8** %9
store i32 1, i32* %11
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%28 = call i8* @arg_string_katcp(%struct.katcp_dispatch* %27, i32 2)
store i8* %28, i8** %8
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 3
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%33 = call i8* @arg_string_katcp(%struct.katcp_dispatch* %32, i32 3)
store i8* %33, i8** %9
br label %34
34: ; preds = %31, %26
br label %35
35: ; preds = %34, %23
%36 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%37 = load i8*, i8** %7
%38 = call %struct.katcp_sensor* @find_sensor_katcp(%struct.katcp_dispatch* %36, i8* %37)
store %struct.katcp_sensor* %38, %struct.katcp_sensor** %6
%39 = load %struct.katcp_sensor*, %struct.katcp_sensor** %6
%40 = icmp eq %struct.katcp_sensor* %39, null
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%43 = load i8*, i8** %7
%44 = call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %42, i32 4, i32* null, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %43)
store i32 -1, i32* %3
br label %84
45: ; preds = %35
%46 = load i8*, i8** %8
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %77
48: ; preds = %45
%49 = load i8*, i8** %8
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %48
store i32 0, i32* %11
store i32 -1, i32* %10
br label %63
53: ; preds = %48
store i32 1, i32* %11
%54 = load i8*, i8** %8
%55 = call i32 @strategy_code_sensor_katcp(i8* %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%60 = load i8*, i8** %8
%61 = call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %59, i32 4, i32* null, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %60)
store i32 -1, i32* %3
br label %84
62: ; preds = %53
br label %63
63: ; preds = %62, %52
%64 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%65 = load %struct.katcp_sensor*, %struct.katcp_sensor** %6
%66 = load i32, i32* %10
%67 = load i32, i32* %11
%68 = load i8*, i8** %9
%69 = call i64 @configure_sensor_katcp(%struct.katcp_dispatch* %64, %struct.katcp_sensor* %65, i32 %66, i32 %67, i8* %68)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %63
%72 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%73 = load i8*, i8** %7
%74 = load i8*, i8** %8
%75 = call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %72, i32 4, i32* null, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %73, i8* %74)
store i32 -1, i32* %3
br label %84
76: ; preds = %63
br label %77
77: ; preds = %76, %45
%78 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %4
%79 = load %struct.katcp_sensor*, %struct.katcp_sensor** %6
%80 = call i64 @reply_sensor_sampling_katcp(%struct.katcp_dispatch* %78, %struct.katcp_sensor* %79)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %77
store i32 -1, i32* %3
br label %84
83: ; preds = %77
store i32 1, i32* %3
br label %84
84: ; preds = %83, %82, %71, %58, %41, %22, %14
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcp_sensor = type { i32 }
@.str = [6 x i8] c"usage\00"
@.str.1 = [18 x i8] c"unknown sensor %s\00"
@.str.2 = [5 x i8] c"auto\00"
@.str.3 = [20 x i8] c"unknown strategy %s\00"
@.str.4 = [46 x i8] c"unable to configure sensor %s for strategy %s\00"
define i32 @sensor_sampling_cmd_katcp(%struct.katcp_dispatch* %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @extra_response_katcp(%struct.katcp_dispatch* %0, i32 -2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %47
6: ; preds = %2
%7 = tail call i8* @arg_string_katcp(%struct.katcp_dispatch* %0, i32 1)
%8 = icmp eq i8* %7, null
br i1 %8, label %47, label %9
9: ; preds = %6
%10 = icmp ugt i32 %1, 2
br i1 %10, label %11, label %20
11: ; preds = %9
%12 = tail call i8* @arg_string_katcp(%struct.katcp_dispatch* %0, i32 2)
%13 = icmp eq i32 %1, 3
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i8* @arg_string_katcp(%struct.katcp_dispatch* %0, i32 3)
br label %16
16: ; preds = %11, %14
%17 = phi i8* [ %15, %14 ], [ null, %11 ]
%18 = tail call %struct.katcp_sensor* @find_sensor_katcp(%struct.katcp_dispatch* %0, i8* %7)
%19 = icmp eq %struct.katcp_sensor* %18, null
br i1 %19, label %23, label %25
20: ; preds = %9
%21 = tail call %struct.katcp_sensor* @find_sensor_katcp(%struct.katcp_dispatch* %0, i8* %7)
%22 = icmp eq %struct.katcp_sensor* %21, null
br i1 %22, label %23, label %42
23: ; preds = %20, %16
%24 = tail call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %0, i32 4, i32* null, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %47
25: ; preds = %16
%26 = icmp eq i8* %12, null
br i1 %26, label %42, label %27
27: ; preds = %25
%28 = tail call i32 @strcmp(i8* %12, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %27
%31 = tail call i32 @strategy_code_sensor_katcp(i8* %12)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %0, i32 4, i32* null, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %47
35: ; preds = %27, %30
%36 = phi i32 [ %31, %30 ], [ -1, %27 ]
%37 = phi i32 [ 1, %30 ], [ 0, %27 ]
%38 = tail call i64 @configure_sensor_katcp(%struct.katcp_dispatch* %0, %struct.katcp_sensor* %18, i32 %36, i32 %37, i8* %17)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = tail call i32 (%struct.katcp_dispatch*, i32, i32*, i8*, i8*, ...) @log_message_katcp(%struct.katcp_dispatch* %0, i32 4, i32* null, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %12)
br label %47
42: ; preds = %20, %35, %25
%43 = phi %struct.katcp_sensor* [ %18, %35 ], [ %18, %25 ], [ %21, %20 ]
%44 = tail call i64 @reply_sensor_sampling_katcp(%struct.katcp_dispatch* %0, %struct.katcp_sensor* %43)
%45 = icmp slt i64 %44, 0
%46 = select i1 %45, i32 -1, i32 1
br label %47
47: ; preds = %42, %6, %40, %33, %23, %4
%48 = phi i32 [ %5, %4 ], [ -1, %23 ], [ -1, %33 ], [ -1, %40 ], [ -1, %6 ], [ %46, %42 ]
ret i32 %48
}