#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 */
unsigned int dectou(char *);
int /*<<< orphan*/ read_registers(int, int, unsigned char *);
char *skipstring(char *);
unsigned int strtofreq(char *);
int /*<<< orphan*/ tune_report(unsigned int, unsigned char);
int /*<<< orphan*/ write_reg(unsigned int, unsigned int);
void command_tune(char *params) {
  if (*params == 0) {
    unsigned char a;
    read_registers(10, 1, &a);
    for (int i = 0; i != 4; ++i)
      tune_report(i, a & 3);
    return;
  }
  unsigned c = dectou(params);
  const char *p = skipstring(params);
  if (*p == 0) {
    unsigned char a;
    read_registers(10, 1, &a);
    tune_report(c, a & 3);
    return;
  }
  unsigned f = strtofreq(skipstring(params));
  write_reg(c * 4 + 16, f);
  write_reg(c * 4 + 17, f >> 8);
  write_reg(c * 4 + 18, f >> 16);
}


x86 assembly (clang, -O0):
<command_tune>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c5 <command_tune+0x65>
mov    $0xa,%edi
mov    $0x1,%esi
lea    -0x9(%rbp),%rdx
call   1040 <read_registers@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
je     11c0 <command_tune+0x60>
mov    -0x10(%rbp),%edi
movzbl -0x9(%rbp),%eax
and    $0x3,%eax
movzbl %al,%esi
call   1060 <tune_report@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1196 <command_tune+0x36>
jmp    1265 <command_tune+0x105>
mov    -0x8(%rbp),%rdi
call   1070 <dectou@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skipstring@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1218 <command_tune+0xb8>
mov    $0xa,%edi
mov    $0x1,%esi
lea    -0x21(%rbp),%rdx
call   1040 <read_registers@plt>
mov    -0x14(%rbp),%edi
movzbl -0x21(%rbp),%eax
and    $0x3,%eax
movzbl %al,%esi
call   1060 <tune_report@plt>
jmp    1265 <command_tune+0x105>
mov    -0x8(%rbp),%rdi
call   1030 <skipstring@plt>
mov    %rax,%rdi
call   1080 <strtofreq@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
shl    $0x2,%edi
add    $0x10,%edi
mov    -0x28(%rbp),%esi
call   1050 <write_reg@plt>
mov    -0x14(%rbp),%edi
shl    $0x2,%edi
add    $0x11,%edi
mov    -0x28(%rbp),%esi
shr    $0x8,%esi
call   1050 <write_reg@plt>
mov    -0x14(%rbp),%edi
shl    $0x2,%edi
add    $0x12,%edi
mov    -0x28(%rbp),%esi
shr    $0x10,%esi
call   1050 <write_reg@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_tune>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     11d1 <command_tune+0x71>
mov    %rdi,%rbx
call   1070 <dectou@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <skipstring@plt>
cmpb   $0x0,(%rax)
je     1227 <command_tune+0xc7>
mov    %rbx,%rdi
call   1030 <skipstring@plt>
mov    %rax,%rdi
call   1080 <strtofreq@plt>
mov    %eax,%ebx
lea    0x10(,%r14,4),%edi
mov    %eax,%esi
call   1050 <write_reg@plt>
lea    0x11(,%r14,4),%edi
mov    %ebx,%esi
shr    $0x8,%esi
call   1050 <write_reg@plt>
lea    0x12(,%r14,4),%edi
shr    $0x10,%ebx
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <write_reg@plt>
lea    0x6(%rsp),%rdx
mov    $0xa,%edi
mov    $0x1,%esi
call   1040 <read_registers@plt>
movzbl 0x6(%rsp),%esi
and    $0x3,%esi
xor    %edi,%edi
call   1060 <tune_report@plt>
movzbl 0x6(%rsp),%esi
and    $0x3,%esi
mov    $0x1,%edi
call   1060 <tune_report@plt>
movzbl 0x6(%rsp),%esi
and    $0x3,%esi
mov    $0x2,%edi
call   1060 <tune_report@plt>
movzbl 0x6(%rsp),%esi
and    $0x3,%esi
mov    $0x3,%edi
jmp    1246 <command_tune+0xe6>
lea    0x7(%rsp),%rdx
mov    $0xa,%edi
mov    $0x1,%esi
call   1040 <read_registers@plt>
movzbl 0x7(%rsp),%esi
and    $0x3,%esi
mov    %r14d,%edi
call   1060 <tune_report@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @command_tune(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %1
%14 = call i32 @read_registers(i32 10, i32 1, i8* %3)
store i32 0, i32* %4
br label %15
15: ; preds = %25, %13
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %4
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = and i32 %21, 3
%23 = trunc i32 %22 to i8
%24 = call i32 @tune_report(i32 %19, i8 zeroext %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %15
28: ; preds = %15
br label %67
29: ; preds = %1
%30 = load i8*, i8** %2
%31 = call i32 @dectou(i8* %30)
store i32 %31, i32* %5
%32 = load i8*, i8** %2
%33 = call i8* @skipstring(i8* %32)
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %29
%39 = call i32 @read_registers(i32 10, i32 1, i8* %7)
%40 = load i32, i32* %5
%41 = load i8, i8* %7
%42 = zext i8 %41 to i32
%43 = and i32 %42, 3
%44 = trunc i32 %43 to i8
%45 = call i32 @tune_report(i32 %40, i8 zeroext %44)
br label %67
46: ; preds = %29
%47 = load i8*, i8** %2
%48 = call i8* @skipstring(i8* %47)
%49 = call i32 @strtofreq(i8* %48)
store i32 %49, i32* %8
%50 = load i32, i32* %5
%51 = mul i32 %50, 4
%52 = add i32 %51, 16
%53 = load i32, i32* %8
%54 = call i32 @write_reg(i32 %52, i32 %53)
%55 = load i32, i32* %5
%56 = mul i32 %55, 4
%57 = add i32 %56, 17
%58 = load i32, i32* %8
%59 = lshr i32 %58, 8
%60 = call i32 @write_reg(i32 %57, i32 %59)
%61 = load i32, i32* %5
%62 = mul i32 %61, 4
%63 = add i32 %62, 18
%64 = load i32, i32* %8
%65 = lshr i32 %64, 16
%66 = call i32 @write_reg(i32 %63, i32 %65)
br label %67
67: ; preds = %46, %38, %28
ret void
}

LLVM IR (-O2):
define void @command_tune(i8* %0) {
%2 = alloca i8
%3 = alloca i8
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = call i32 @read_registers(i32 10, i32 1, i8* %2)
%8 = load i8, i8* %2
%9 = and i8 %8, 3
%10 = call i32 @tune_report(i32 0, i8 zeroext %9)
%11 = load i8, i8* %2
%12 = and i8 %11, 3
%13 = call i32 @tune_report(i32 1, i8 zeroext %12)
%14 = load i8, i8* %2
%15 = and i8 %14, 3
%16 = call i32 @tune_report(i32 2, i8 zeroext %15)
%17 = load i8, i8* %2
%18 = and i8 %17, 3
%19 = call i32 @tune_report(i32 3, i8 zeroext %18)
br label %42
20: ; preds = %1
%21 = tail call i32 @dectou(i8* %0)
%22 = tail call i8* @skipstring(i8* %0)
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = call i32 @read_registers(i32 10, i32 1, i8* %3)
%27 = load i8, i8* %3
%28 = and i8 %27, 3
%29 = call i32 @tune_report(i32 %21, i8 zeroext %28)
br label %42
30: ; preds = %20
%31 = tail call i8* @skipstring(i8* %0)
%32 = tail call i32 @strtofreq(i8* %31)
%33 = shl i32 %21, 2
%34 = add i32 %33, 16
%35 = tail call i32 @write_reg(i32 %34, i32 %32)
%36 = add i32 %33, 17
%37 = lshr i32 %32, 8
%38 = tail call i32 @write_reg(i32 %36, i32 %37)
%39 = add i32 %33, 18
%40 = lshr i32 %32, 16
%41 = tail call i32 @write_reg(i32 %39, i32 %40)
br label %42
42: ; preds = %25, %30, %6
ret void
}