void command_gain(char *params) {
  unsigned c = dectou(params);
  const char *p = skipstring(params);
  unsigned g = dectou(p);
  p = skipstring(p);
  if (*p)
    g = g + 16 * dectou(p);
  else if (c == 2 && g < 16)
    g *= 17;
  write_reg(((c)*4 + 19), g);
}


x86 assembly (clang, -O0):
<command_gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <dectou@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <skipstring@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <dectou@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1030 <skipstring@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11aa <command_gain+0x7a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <dectou@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
shl    $0x4,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <command_gain+0x9a>
cmpl   $0x2,-0xc(%rbp)
jne    11c5 <command_gain+0x95>
cmpl   $0x10,-0x1c(%rbp)
jae    11c5 <command_gain+0x95>
imul   $0x11,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <command_gain+0x9a>
mov    -0xc(%rbp),%edi
shl    $0x2,%edi
add    $0x13,%edi
mov    -0x1c(%rbp),%esi
mov    $0x0,%al
call   1040 <write_reg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_gain>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <dectou@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
xor    %eax,%eax
call   1030 <skipstring@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <dectou@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <skipstring@plt>
movslq %eax,%rdi
cmpb   $0x0,(%rdi)
je     117c <command_gain+0x4c>
xor    %eax,%eax
call   1050 <dectou@plt>
mov    %eax,%esi
shl    $0x4,%esi
add    %ebp,%esi
jmp    1190 <command_gain+0x60>
mov    %ebp,%esi
shl    $0x4,%esi
add    %ebp,%esi
cmp    $0x10,%ebp
cmovae %ebp,%esi
cmp    $0x2,%r14d
cmovne %ebp,%esi
lea    0x13(,%r14,4),%edi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <write_reg@plt>

LLVM IR (-O0):
define void @command_gain(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @dectou to i32 (i8*, ...)*)(i8* %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @skipstring to i32 (i8*, ...)*)(i8* %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = call i32 (i8*, ...) bitcast (i32 (...)* @dectou to i32 (i8*, ...)*)(i8* %12)
store i32 %13, i32* %5
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @skipstring to i32 (i8*, ...)*)(i8* %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %1
%22 = load i32, i32* %5
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @dectou to i32 (i8*, ...)*)(i8* %23)
%25 = mul nsw i32 16, %24
%26 = add i32 %22, %25
store i32 %26, i32* %5
br label %37
27: ; preds = %1
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* %5
%32 = icmp ult i32 %31, 16
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %5
%35 = mul i32 %34, 17
store i32 %35, i32* %5
br label %36
36: ; preds = %33, %30, %27
br label %37
37: ; preds = %36, %21
%38 = load i32, i32* %3
%39 = mul i32 %38, 4
%40 = add i32 %39, 19
%41 = load i32, i32* %5
%42 = call i32 (i32, i32, ...) bitcast (i32 (...)* @write_reg to i32 (i32, i32, ...)*)(i32 %40, i32 %41)
ret void
}

LLVM IR (-O2):
define void @command_gain(i8* %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dectou to i32 (i8*, ...)*)(i8* %0)
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @skipstring to i32 (i8*, ...)*)(i8* %0)
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dectou to i32 (i8*, ...)*)(i8* %5)
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @skipstring to i32 (i8*, ...)*)(i8* %5)
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = tail call i32 (i8*, ...) bitcast (i32 (...)* @dectou to i32 (i8*, ...)*)(i8* %9)
%14 = shl nsw i32 %13, 4
%15 = add i32 %14, %6
br label %22
16: ; preds = %1
%17 = icmp eq i32 %2, 2
%18 = icmp ult i32 %6, 16
%19 = select i1 %17, i1 %18, i1 false
%20 = mul i32 %6, 17
%21 = select i1 %19, i32 %20, i32 %6
br label %22
22: ; preds = %16, %12
%23 = phi i32 [ %15, %12 ], [ %21, %16 ]
%24 = shl i32 %2, 2
%25 = add i32 %24, 19
%26 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @write_reg to i32 (i32, i32, ...)*)(i32 %25, i32 %23)
ret void
}