#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 */
typedef char uint8_t;
struct netio {
  int dummy;
};
struct atrf_dsc {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int atrf_buf_read(struct atrf_dsc *, char *, int);
char *atrf_driver_spec(struct atrf_dsc *, int);
int /*<<< orphan*/ atrf_reset(struct atrf_dsc *);
int /*<<< orphan*/ atrf_reset_rf(struct atrf_dsc *);
int /*<<< orphan*/ atrf_test_mode(struct atrf_dsc *);
int netio_printf(struct netio *, char *, ...);
int netio_write(struct netio *, char *, int);
int /*<<< orphan*/ strcasecmp(char const *, char *);
int cmd_zero(struct atrf_dsc *dsc, struct netio *netio, const char *cmd) {
  if (!strcasecmp(cmd, "spec")) {
    const char *spec = atrf_driver_spec(dsc, 1);
    if (spec)
      return netio_printf(netio, "+%s\n", spec);
    else
      return netio_printf(netio, "-can't obtain specification\n");
  }
  if (!strcasecmp(cmd, "reset")) {
    atrf_reset(dsc);
    return netio_printf(netio, "+\n");
  }
  if (!strcasecmp(cmd, "reset_rf")) {
    atrf_reset_rf(dsc);
    return netio_printf(netio, "+\n");
  }
  if (!strcasecmp(cmd, "test")) {
    atrf_test_mode(dsc);
    return netio_printf(netio, "+\n");
  }
  if (!strcasecmp(cmd, "read")) {
    uint8_t buf[128 + 1];
    int got;
    got = atrf_buf_read(dsc, buf, sizeof(buf));
    if (got < 0)
      return netio_printf(netio, "-I/O error\n");
    if (netio_printf(netio, "+%d ", got) < 0)
      return -1;
    buf[got] = '\n';
    return netio_write(netio, buf, got + 1);
  }
  return netio_printf(netio, "-unrecognized command\n");
}


x86 assembly (clang, -O0):
<cmd_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1205 <cmd_zero+0x85>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <atrf_driver_spec@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11eb <cmd_zero+0x6b>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x18(%rbp),%rdi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x20(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1241 <cmd_zero+0xc1>
mov    -0x10(%rbp),%rdi
call   1050 <atrf_reset@plt>
mov    -0x18(%rbp),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x20(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    127d <cmd_zero+0xfd>
mov    -0x10(%rbp),%rdi
call   1060 <atrf_reset_rf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x20(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    12b9 <cmd_zero+0x139>
mov    -0x10(%rbp),%rdi
call   1070 <atrf_test_mode@plt>
mov    -0x18(%rbp),%rdi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x20(%rbp),%rdi
lea    0xd7a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1371 <cmd_zero+0x1f1>
mov    -0x10(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x81,%edx
call   1080 <atrf_buf_read@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jge    1314 <cmd_zero+0x194>
mov    -0x18(%rbp),%rdi
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x18(%rbp),%rdi
mov    -0xb4(%rbp),%edx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
cmp    $0x0,%eax
jge    1341 <cmd_zero+0x1c1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
movslq -0xb4(%rbp),%rax
movb   $0xa,-0xb0(%rbp,%rax,1)
0a
mov    -0x18(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
add    $0x1,%edx
call   10a0 <netio_write@plt>
mov    %eax,-0x4(%rbp)
jmp    1386 <cmd_zero+0x206>
mov    -0x18(%rbp),%rdi
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   1090 <netio_printf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_zero>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe64(%rip),%rsi
mov    %rdx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11fd <cmd_zero+0x7d>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     122f <cmd_zero+0xaf>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1239 <cmd_zero+0xb9>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     124c <cmd_zero+0xcc>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1271 <cmd_zero+0xf1>
lea    0xe59(%rip),%rsi
jmp    125b <cmd_zero+0xdb>
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <atrf_driver_spec@plt>
test   %rax,%rax
je     1243 <cmd_zero+0xc3>
lea    0xdef(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <netio_printf@plt>
mov    %r15,%rdi
call   1050 <atrf_reset@plt>
jmp    1254 <cmd_zero+0xd4>
mov    %r15,%rdi
call   1060 <atrf_reset_rf@plt>
jmp    1254 <cmd_zero+0xd4>
lea    0xdc0(%rip),%rsi
jmp    125b <cmd_zero+0xdb>
mov    %r15,%rdi
call   1070 <atrf_test_mode@plt>
lea    0xdd2(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <netio_printf@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
mov    $0x81,%edx
call   1080 <atrf_buf_read@plt>
test   %eax,%eax
js     12b6 <cmd_zero+0x136>
mov    %eax,%ebx
lea    0xdc1(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <netio_printf@plt>
test   %eax,%eax
js     12c9 <cmd_zero+0x149>
mov    %ebx,%eax
movb   $0xa,(%rsp,%rax,1)
add    $0x1,%ebx
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   10a0 <netio_write@plt>
jmp    12ce <cmd_zero+0x14e>
lea    0xd86(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <netio_printf@plt>
jmp    12ce <cmd_zero+0x14e>
mov    $0xffffffff,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.atrf_dsc = type { i32 }
%struct.netio = type { i32 }
@.str = [5 x i8] c"spec\00"
@.str.1 = [5 x i8] c"+%s\0A\00"
@.str.2 = [29 x i8] c"-can't obtain specification\0A\00"
@.str.3 = [6 x i8] c"reset\00"
@.str.4 = [3 x i8] c"+\0A\00"
@.str.5 = [9 x i8] c"reset_rf\00"
@.str.6 = [5 x i8] c"test\00"
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [12 x i8] c"-I/O error\0A\00"
@.str.9 = [5 x i8] c"+%d \00"
@.str.10 = [23 x i8] c"-unrecognized command\0A\00"
define i32 @cmd_zero(%struct.atrf_dsc* %0, %struct.netio* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.atrf_dsc*
%6 = alloca %struct.netio*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [129 x i8]
%10 = alloca i32
store %struct.atrf_dsc* %0, %struct.atrf_dsc** %5
store %struct.netio* %1, %struct.netio** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @strcasecmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %3
%15 = load %struct.atrf_dsc*, %struct.atrf_dsc** %5
%16 = call i8* @atrf_driver_spec(%struct.atrf_dsc* %15, i32 1)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load %struct.netio*, %struct.netio** %6
%21 = load i8*, i8** %8
%22 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 %22, i32* %4
br label %84
23: ; preds = %14
%24 = load %struct.netio*, %struct.netio** %6
%25 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 %25, i32* %4
br label %84
26: ; preds = %3
%27 = load i8*, i8** %7
%28 = call i32 @strcasecmp(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = load %struct.atrf_dsc*, %struct.atrf_dsc** %5
%32 = call i32 @atrf_reset(%struct.atrf_dsc* %31)
%33 = load %struct.netio*, %struct.netio** %6
%34 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %34, i32* %4
br label %84
35: ; preds = %26
%36 = load i8*, i8** %7
%37 = call i32 @strcasecmp(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %35
%40 = load %struct.atrf_dsc*, %struct.atrf_dsc** %5
%41 = call i32 @atrf_reset_rf(%struct.atrf_dsc* %40)
%42 = load %struct.netio*, %struct.netio** %6
%43 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %43, i32* %4
br label %84
44: ; preds = %35
%45 = load i8*, i8** %7
%46 = call i32 @strcasecmp(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%47 = icmp ne i32 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %44
%49 = load %struct.atrf_dsc*, %struct.atrf_dsc** %5
%50 = call i32 @atrf_test_mode(%struct.atrf_dsc* %49)
%51 = load %struct.netio*, %struct.netio** %6
%52 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %52, i32* %4
br label %84
53: ; preds = %44
%54 = load i8*, i8** %7
%55 = call i32 @strcasecmp(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %81, label %57
57: ; preds = %53
%58 = load %struct.atrf_dsc*, %struct.atrf_dsc** %5
%59 = getelementptr inbounds [129 x i8], [129 x i8]* %9, i64 0, i64 0
%60 = call i32 @atrf_buf_read(%struct.atrf_dsc* %58, i8* %59, i32 129)
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %57
%64 = load %struct.netio*, %struct.netio** %6
%65 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 %65, i32* %4
br label %84
66: ; preds = %57
%67 = load %struct.netio*, %struct.netio** %6
%68 = load i32, i32* %10
%69 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %68)
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %66
store i32 -1, i32* %4
br label %84
72: ; preds = %66
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [129 x i8], [129 x i8]* %9, i64 0, i64 %74
store i8 10, i8* %75
%76 = load %struct.netio*, %struct.netio** %6
%77 = getelementptr inbounds [129 x i8], [129 x i8]* %9, i64 0, i64 0
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
%80 = call i32 @netio_write(%struct.netio* %76, i8* %77, i32 %79)
store i32 %80, i32* %4
br label %84
81: ; preds = %53
%82 = load %struct.netio*, %struct.netio** %6
%83 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %82, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
store i32 %83, i32* %4
br label %84
84: ; preds = %81, %72, %71, %63, %48, %39, %30, %23, %19
%85 = load i32, i32* %4
ret i32 %85
}

LLVM IR (-O2):
%struct.atrf_dsc = type { i32 }
%struct.netio = type { i32 }
@.str = [5 x i8] c"spec\00"
@.str.1 = [5 x i8] c"+%s\0A\00"
@.str.2 = [29 x i8] c"-can't obtain specification\0A\00"
@.str.3 = [6 x i8] c"reset\00"
@.str.4 = [3 x i8] c"+\0A\00"
@.str.5 = [9 x i8] c"reset_rf\00"
@.str.6 = [5 x i8] c"test\00"
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [12 x i8] c"-I/O error\0A\00"
@.str.9 = [5 x i8] c"+%d \00"
@.str.10 = [23 x i8] c"-unrecognized command\0A\00"
define i32 @cmd_zero(%struct.atrf_dsc* %0, %struct.netio* %1, i8* nocapture %2) {
%4 = alloca [129 x i8]
%5 = tail call i32 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = tail call i8* @atrf_driver_spec(%struct.atrf_dsc* %0, i32 1)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %53
12: ; preds = %7
%13 = tail call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %53
14: ; preds = %3
%15 = tail call i32 @strcasecmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @atrf_reset(%struct.atrf_dsc* %0)
%19 = tail call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %53
20: ; preds = %14
%21 = tail call i32 @strcasecmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @atrf_reset_rf(%struct.atrf_dsc* %0)
%25 = tail call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %53
26: ; preds = %20
%27 = tail call i32 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = tail call i32 @atrf_test_mode(%struct.atrf_dsc* %0)
%31 = tail call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %53
32: ; preds = %26
%33 = tail call i32 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %51
35: ; preds = %32
%36 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 0
%37 = call i32 @atrf_buf_read(%struct.atrf_dsc* %0, i8* %36, i32 129)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %49
41: ; preds = %35
%42 = call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %37)
%43 = icmp slt i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = zext i32 %37 to i64
%46 = getelementptr inbounds [129 x i8], [129 x i8]* %4, i64 0, i64 %45
store i8 10, i8* %46
%47 = add nuw nsw i32 %37, 1
%48 = call i32 @netio_write(%struct.netio* %1, i8* %36, i32 %47)
br label %49
49: ; preds = %41, %44, %39
%50 = phi i32 [ %40, %39 ], [ %48, %44 ], [ -1, %41 ]
br label %53
51: ; preds = %32
%52 = tail call i32 (%struct.netio*, i8*, ...) @netio_printf(%struct.netio* %1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %53
53: ; preds = %10, %12, %51, %49, %29, %23, %17
%54 = phi i32 [ %52, %51 ], [ %50, %49 ], [ %31, %29 ], [ %25, %23 ], [ %19, %17 ], [ %11, %10 ], [ %13, %12 ]
ret i32 %54
}