#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 int uint16_t;
typedef int /*<<< orphan*/ code;

/* Variables and functions */
int /*<<< orphan*/ rpc_adc_enable_channel();
int /*<<< orphan*/ rpc_adc_sample();
int /*<<< orphan*/ rpc_dac_enable_channel();
int /*<<< orphan*/ rpc_dac_set_output();
int /*<<< orphan*/ rpc_gpio_get_pin();
int /*<<< orphan*/ rpc_gpio_set_pin();
int /*<<< orphan*/ rpc_gpio_setup_input_pin();
int /*<<< orphan*/ rpc_gpio_setup_output_pin();
int /*<<< orphan*/ rpc_pwm_enable_channel();
int /*<<< orphan*/ rpc_pwm_enable_timer();
int /*<<< orphan*/ rpc_pwm_set_channel_duty_cycle();
int usart_in_waiting();
int /*<<< orphan*/ usart_read(int *, int);
void rpc_listen(void) {
  uint16_t code;
  while (1) {
    while (usart_in_waiting() < 2)
      ;
    usart_read(&code, sizeof(code));
    if (code == 0x0000)
      rpc_gpio_setup_input_pin();
    else if (code == 0x0001)
      rpc_gpio_setup_output_pin();
    else if (code == 0x0002)
      rpc_gpio_set_pin();
    else if (code == 0x0003)
      rpc_gpio_get_pin();
    else if (code == 0x0100)
      rpc_dac_enable_channel();
    else if (code == 0x0101)
      rpc_dac_set_output();
    else if (code == 0x0200)
      rpc_pwm_enable_channel();
    else if (code == 0x0201)
      rpc_pwm_enable_timer();
    else if (code == 0x0202)
      rpc_pwm_set_channel_duty_cycle();
    else if (code == 0x0300)
      rpc_adc_enable_channel();
    else if (code == 0x0301)
      rpc_adc_sample();
  }
}


x86 assembly (clang, -O0):
<rpc_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
jmp    11dd <rpc_listen+0xd>
mov    $0x0,%al
call   1050 <usart_in_waiting@plt>
cmp    $0x2,%eax
jge    11f2 <rpc_listen+0x22>
jmp    11dd <rpc_listen+0xd>
lea    -0x4(%rbp),%rdi
mov    $0x4,%esi
call   1040 <usart_read@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1216 <rpc_listen+0x46>
mov    $0x0,%al
call   1070 <rpc_gpio_setup_input_pin@plt>
jmp    1334 <rpc_listen+0x164>
cmpl   $0x1,-0x4(%rbp)
jne    122c <rpc_listen+0x5c>
mov    $0x0,%al
call   10d0 <rpc_gpio_setup_output_pin@plt>
jmp    132f <rpc_listen+0x15f>
cmpl   $0x2,-0x4(%rbp)
jne    1242 <rpc_listen+0x72>
mov    $0x0,%al
call   1030 <rpc_gpio_set_pin@plt>
jmp    132a <rpc_listen+0x15a>
cmpl   $0x3,-0x4(%rbp)
jne    1258 <rpc_listen+0x88>
mov    $0x0,%al
call   10b0 <rpc_gpio_get_pin@plt>
jmp    1325 <rpc_listen+0x155>
cmpl   $0x100,-0x4(%rbp)
jne    1271 <rpc_listen+0xa1>
mov    $0x0,%al
call   10c0 <rpc_dac_enable_channel@plt>
jmp    1320 <rpc_listen+0x150>
cmpl   $0x101,-0x4(%rbp)
jne    128a <rpc_listen+0xba>
mov    $0x0,%al
call   10f0 <rpc_dac_set_output@plt>
jmp    131b <rpc_listen+0x14b>
cmpl   $0x200,-0x4(%rbp)
jne    12a3 <rpc_listen+0xd3>
mov    $0x0,%al
call   1090 <rpc_pwm_enable_channel@plt>
jmp    1316 <rpc_listen+0x146>
cmpl   $0x201,-0x4(%rbp)
jne    12bc <rpc_listen+0xec>
mov    $0x0,%al
call   1060 <rpc_pwm_enable_timer@plt>
jmp    1311 <rpc_listen+0x141>
cmpl   $0x202,-0x4(%rbp)
jne    12d5 <rpc_listen+0x105>
mov    $0x0,%al
call   10e0 <rpc_pwm_set_channel_duty_cycle@plt>
jmp    130c <rpc_listen+0x13c>
cmpl   $0x300,-0x4(%rbp)
jne    12ee <rpc_listen+0x11e>
mov    $0x0,%al
call   1080 <rpc_adc_enable_channel@plt>
jmp    1307 <rpc_listen+0x137>
cmpl   $0x301,-0x4(%rbp)
jne    1302 <rpc_listen+0x132>
mov    $0x0,%al
call   10a0 <rpc_adc_sample@plt>
jmp    1307 <rpc_listen+0x137>
jmp    130c <rpc_listen+0x13c>
jmp    1311 <rpc_listen+0x141>
jmp    1316 <rpc_listen+0x146>
jmp    131b <rpc_listen+0x14b>
jmp    1320 <rpc_listen+0x150>
jmp    1325 <rpc_listen+0x155>
jmp    132a <rpc_listen+0x15a>
jmp    132f <rpc_listen+0x15f>
jmp    1334 <rpc_listen+0x164>
jmp    11d8 <rpc_listen+0x8>

x86 assembly (clang, -O2):
<rpc_listen>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
lea    0xe20(%rip),%r14
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   1080 <rpc_adc_enable_channel@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <usart_in_waiting@plt>
cmp    $0x2,%eax
jl     11f0 <rpc_listen+0x20>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <usart_read@plt>
mov    0x4(%rsp),%eax
cmp    $0x1ff,%eax
jg     1230 <rpc_listen+0x60>
cmp    $0x3,%eax
ja     1255 <rpc_listen+0x85>
mov    %eax,%eax
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
xor    %eax,%eax
call   1070 <rpc_gpio_setup_input_pin@plt>
jmp    11f0 <rpc_listen+0x20>
nopl   (%rax)
cmp    $0x201,%eax
jle    126c <rpc_listen+0x9c>
cmp    $0x202,%eax
je     12ae <rpc_listen+0xde>
cmp    $0x300,%eax
je     11e2 <rpc_listen+0x12>
cmp    $0x301,%eax
jne    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   10a0 <rpc_adc_sample@plt>
jmp    11f0 <rpc_listen+0x20>
cmp    $0x100,%eax
je     12ba <rpc_listen+0xea>
cmp    $0x101,%eax
jne    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   10f0 <rpc_dac_set_output@plt>
jmp    11f0 <rpc_listen+0x20>
cmp    $0x200,%eax
je     12c6 <rpc_listen+0xf6>
cmp    $0x201,%eax
jne    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   1060 <rpc_pwm_enable_timer@plt>
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   10d0 <rpc_gpio_setup_output_pin@plt>
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   1030 <rpc_gpio_set_pin@plt>
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   10b0 <rpc_gpio_get_pin@plt>
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   10e0 <rpc_pwm_set_channel_duty_cycle@plt>
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   10c0 <rpc_dac_enable_channel@plt>
jmp    11f0 <rpc_listen+0x20>
xor    %eax,%eax
call   1090 <rpc_pwm_enable_channel@plt>
jmp    11f0 <rpc_listen+0x20>

LLVM IR (-O0):
define void @rpc_listen() {
%1 = alloca i32
br label %2
2: ; preds = %0, %73
br label %3
3: ; preds = %6, %2
%4 = call i32 (...) @usart_in_waiting()
%5 = icmp slt i32 %4, 2
br i1 %5, label %6, label %7
6: ; preds = %3
br label %3
7: ; preds = %3
%8 = call i32 @usart_read(i32* %1, i32 4)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 (...) @rpc_gpio_setup_input_pin()
br label %73
13: ; preds = %7
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (...) @rpc_gpio_setup_output_pin()
br label %72
18: ; preds = %13
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (...) @rpc_gpio_set_pin()
br label %71
23: ; preds = %18
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (...) @rpc_gpio_get_pin()
br label %70
28: ; preds = %23
%29 = load i32, i32* %1
%30 = icmp eq i32 %29, 256
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (...) @rpc_dac_enable_channel()
br label %69
33: ; preds = %28
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 257
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (...) @rpc_dac_set_output()
br label %68
38: ; preds = %33
%39 = load i32, i32* %1
%40 = icmp eq i32 %39, 512
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (...) @rpc_pwm_enable_channel()
br label %67
43: ; preds = %38
%44 = load i32, i32* %1
%45 = icmp eq i32 %44, 513
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (...) @rpc_pwm_enable_timer()
br label %66
48: ; preds = %43
%49 = load i32, i32* %1
%50 = icmp eq i32 %49, 514
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (...) @rpc_pwm_set_channel_duty_cycle()
br label %65
53: ; preds = %48
%54 = load i32, i32* %1
%55 = icmp eq i32 %54, 768
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (...) @rpc_adc_enable_channel()
br label %64
58: ; preds = %53
%59 = load i32, i32* %1
%60 = icmp eq i32 %59, 769
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 (...) @rpc_adc_sample()
br label %63
63: ; preds = %61, %58
br label %64
64: ; preds = %63, %56
br label %65
65: ; preds = %64, %51
br label %66
66: ; preds = %65, %46
br label %67
67: ; preds = %66, %41
br label %68
68: ; preds = %67, %36
br label %69
69: ; preds = %68, %31
br label %70
70: ; preds = %69, %26
br label %71
71: ; preds = %70, %21
br label %72
72: ; preds = %71, %16
br label %73
73: ; preds = %72, %11
br label %2
}

LLVM IR (-O2):
define void @rpc_listen() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %6, %0
%4 = call i32 (...) @usart_in_waiting()
%5 = icmp slt i32 %4, 2
br i1 %5, label %6, label %7
6: ; preds = %3, %7, %12, %16, %20, %24, %28, %30, %26, %22, %18, %14, %10
br label %3
7: ; preds = %3
%8 = call i32 @usart_read(i32* %1, i32 4)
%9 = load i32, i32* %1
switch i32 %9, label %6 [
i32 0, label %10
i32 1, label %12
i32 2, label %14
i32 3, label %16
i32 256, label %18
i32 257, label %20
i32 512, label %22
i32 513, label %24
i32 514, label %26
i32 768, label %28
i32 769, label %30
]
10: ; preds = %7
%11 = call i32 (...) @rpc_gpio_setup_input_pin()
br label %6
12: ; preds = %7
%13 = call i32 (...) @rpc_gpio_setup_output_pin()
br label %6
14: ; preds = %7
%15 = call i32 (...) @rpc_gpio_set_pin()
br label %6
16: ; preds = %7
%17 = call i32 (...) @rpc_gpio_get_pin()
br label %6
18: ; preds = %7
%19 = call i32 (...) @rpc_dac_enable_channel()
br label %6
20: ; preds = %7
%21 = call i32 (...) @rpc_dac_set_output()
br label %6
22: ; preds = %7
%23 = call i32 (...) @rpc_pwm_enable_channel()
br label %6
24: ; preds = %7
%25 = call i32 (...) @rpc_pwm_enable_timer()
br label %6
26: ; preds = %7
%27 = call i32 (...) @rpc_pwm_set_channel_duty_cycle()
br label %6
28: ; preds = %7
%29 = call i32 (...) @rpc_adc_enable_channel()
br label %6
30: ; preds = %7
%31 = call i32 (...) @rpc_adc_sample()
br label %6
}