#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ v3_analog_inputs_enable(int);
int v3_analog_read(short);
int /*<<< orphan*/ v3_open();
int /*<<< orphan*/ v3_servo_disconnect(short);
int /*<<< orphan*/ v3_servo_set(short, short);
int /*<<< orphan*/ v3_work();
int /*<<< orphan*/ write(int, char *, int);
int main() {
  v3_open();
  v3_analog_inputs_enable((1 << 0) | (1 << 1) | (1 << 2));
  short val0, val1;
  int ret;
  char cmd;
  do {
    write(1, "v3> ", 6);
    scanf("%c %hd", &cmd, &val0);
    if (cmd == 'd')
      v3_servo_disconnect(val0);
    else if (cmd == 's') {
      scanf("%hd", &val1);
      v3_servo_set(val0, val1);
    } else if (cmd == 'a') {
      printf("value=%d\n", v3_analog_read(val0));
    }
    v3_work();
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <v3_open@plt>
mov    $0x7,%edi
call   1070 <v3_analog_inputs_enable@plt>
mov    $0x1,%edi
lea    0xe44(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
lea    0xe38(%rip),%rdi
lea    -0xd(%rbp),%rsi
lea    -0x6(%rbp),%rdx
mov    $0x0,%al
call   1090 <scanf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x64,%eax
jne    11f7 <main+0x67>
movswl -0x6(%rbp),%edi
call   1030 <v3_servo_disconnect@plt>
jmp    1259 <main+0xc9>
movsbl -0xd(%rbp),%eax
cmp    $0x73,%eax
jne    122b <main+0x9b>
lea    0xdfd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    -0x6(%rbp),%ax
movswl %ax,%edi
movswl -0x8(%rbp),%esi
call   10b0 <v3_servo_set@plt>
jmp    1254 <main+0xc4>
movsbl -0xd(%rbp),%eax
cmp    $0x61,%eax
jne    124f <main+0xbf>
movswl -0x6(%rbp),%edi
call   1060 <v3_analog_read@plt>
mov    %eax,%esi
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
jmp    1254 <main+0xc4>
jmp    1259 <main+0xc9>
mov    $0x0,%al
call   1080 <v3_work@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11b0 <main+0x20>
jmp    126f <main+0xdf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10a0 <v3_open@plt>
mov    $0x7,%edi
call   1070 <v3_analog_inputs_enable@plt>
lea    0xe4d(%rip),%r14
lea    0xe4b(%rip),%r15
lea    0x5(%rsp),%r12
lea    0x2(%rsp),%rbx
lea    0xe3d(%rip),%rbp
lea    0x6(%rsp),%r13
jmp    1203 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
movswl 0x2(%rsp),%edi
movswl 0x6(%rsp),%esi
call   10b0 <v3_servo_set@plt>
xor    %eax,%eax
call   1080 <v3_work@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
movzbl 0x5(%rsp),%eax
cmp    $0x61,%al
je     1250 <main+0xc0>
cmp    $0x73,%al
je     11e0 <main+0x50>
cmp    $0x64,%al
jne    11fc <main+0x6c>
movswl 0x2(%rsp),%edi
call   1030 <v3_servo_disconnect@plt>
jmp    11fc <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movswl 0x2(%rsp),%edi
call   1060 <v3_analog_read@plt>
lea    0xdab(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
jmp    11fc <main+0x6c>

LLVM IR (-O0):
@.str = [5 x i8] c"v3> \00"
@.str.1 = [7 x i8] c"%c %hd\00"
@.str.2 = [4 x i8] c"%hd\00"
@.str.3 = [10 x i8] c"value=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 (...) @v3_open()
%7 = call i32 @v3_analog_inputs_enable(i32 7)
br label %8
8: ; preds = %38, %0
%9 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5, i16* %2)
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i16, i16* %2
%16 = call i32 @v3_servo_disconnect(i16 signext %15)
br label %36
17: ; preds = %8
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 115
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%23 = load i16, i16* %2
%24 = load i16, i16* %3
%25 = call i32 @v3_servo_set(i16 signext %23, i16 signext %24)
br label %35
26: ; preds = %17
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 97
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i16, i16* %2
%32 = call i32 @v3_analog_read(i16 signext %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %30, %26
br label %35
35: ; preds = %34, %21
br label %36
36: ; preds = %35, %14
%37 = call i32 (...) @v3_work()
br label %38
38: ; preds = %36
br i1 true, label %8, label %39
39: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"v3> \00"
@.str.1 = [7 x i8] c"%c %hd\00"
@.str.2 = [4 x i8] c"%hd\00"
@.str.3 = [10 x i8] c"value=%d\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8
%4 = tail call i32 (...) @v3_open()
%5 = tail call i32 @v3_analog_inputs_enable(i32 7)
%6 = bitcast i16* %1 to i8*
%7 = bitcast i16* %2 to i8*
br label %8
8: ; preds = %24, %0
%9 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %3, i16* %1)
%11 = load i8, i8* %3
switch i8 %11, label %24 [
i8 100, label %12
i8 115, label %15
i8 97, label %20
]
12: ; preds = %8
%13 = load i16, i16* %1
%14 = call i32 @v3_servo_disconnect(i16 signext %13)
br label %24
15: ; preds = %8
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%17 = load i16, i16* %1
%18 = load i16, i16* %2
%19 = call i32 @v3_servo_set(i16 signext %17, i16 signext %18)
br label %24
20: ; preds = %8
%21 = load i16, i16* %1
%22 = call i32 @v3_analog_read(i16 signext %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %8, %15, %20, %12
%25 = call i32 (...) @v3_work()
br label %8
}