#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*/ scanf(char *, ...);
int /*<<< orphan*/ v4_open();
int /*<<< orphan*/ v4_servo_set(short, short);
int /*<<< orphan*/ v4_servo_stop(short);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  v4_open();
  short val0, val1;
  char cmd;
  do {
    write(1, "v4> ", 6);
    scanf("%c %hd", &cmd, &val0);
    if (cmd == 'd')
      v4_servo_stop(val0);
    else if (cmd == 's') {
      scanf("%hd", &val1);
      v4_servo_set(val0, val1);
    }
  } 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   1050 <v4_open@plt>
mov    $0x1,%edi
lea    0xe8e(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
lea    0xe82(%rip),%rdi
lea    -0x9(%rbp),%rsi
lea    -0x6(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x64,%eax
jne    11ad <main+0x5d>
movswl -0x6(%rbp),%edi
call   1040 <v4_servo_stop@plt>
jmp    11e1 <main+0x91>
movsbl -0x9(%rbp),%eax
cmp    $0x73,%eax
jne    11dc <main+0x8c>
lea    0xe47(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x6(%rbp),%ax
movswl %ax,%edi
movswl -0x8(%rbp),%esi
call   1070 <v4_servo_set@plt>
jmp    11e1 <main+0x91>
jmp    11e6 <main+0x96>
mov    $0x1,%al
test   $0x1,%al
jne    1166 <main+0x16>
jmp    11f5 <main+0xa5>
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   1050 <v4_open@plt>
lea    0xe97(%rip),%r14
lea    0xe95(%rip),%r15
lea    0x3(%rsp),%r12
lea    0x4(%rsp),%rbx
lea    0xe87(%rip),%r13
lea    0x6(%rsp),%rbp
jmp    11ac <main+0x5c>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movswl 0x4(%rsp),%edi
movswl 0x6(%rsp),%esi
call   1070 <v4_servo_set@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
movzbl 0x3(%rsp),%eax
cmp    $0x73,%al
je     1190 <main+0x40>
cmp    $0x64,%al
jne    11ac <main+0x5c>
movswl 0x4(%rsp),%edi
call   1040 <v4_servo_stop@plt>
jmp    11ac <main+0x5c>

LLVM IR (-O0):
@.str = [5 x i8] c"v4> \00"
@.str.1 = [7 x i8] c"%c %hd\00"
@.str.2 = [4 x i8] c"%hd\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32 (...) @v4_open()
br label %6
6: ; preds = %26, %0
%7 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6)
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4, i16* %2)
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 100
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i16, i16* %2
%14 = call i32 @v4_servo_stop(i16 signext %13)
br label %25
15: ; preds = %6
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 115
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%21 = load i16, i16* %2
%22 = load i16, i16* %3
%23 = call i32 @v4_servo_set(i16 signext %21, i16 signext %22)
br label %24
24: ; preds = %19, %15
br label %25
25: ; preds = %24, %12
br label %26
26: ; preds = %25
br i1 true, label %6, label %27
27: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"v4> \00"
@.str.1 = [7 x i8] c"%c %hd\00"
@.str.2 = [4 x i8] c"%hd\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i8
%4 = tail call i32 (...) @v4_open()
%5 = bitcast i16* %1 to i8*
%6 = bitcast i16* %2 to i8*
br label %7
7: ; preds = %11, %0
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6)
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %3, i16* %1)
%10 = load i8, i8* %3
switch i8 %10, label %11 [
i8 100, label %12
i8 115, label %15
]
11: ; preds = %7, %12, %15
br label %7
12: ; preds = %7
%13 = load i16, i16* %1
%14 = call i32 @v4_servo_stop(i16 signext %13)
br label %11
15: ; preds = %7
%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 @v4_servo_set(i16 signext %17, i16 signext %18)
br label %11
}