#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 hextou(char const *);
char *skipstring(char const *);
scalar_t__ streq(char const *, char *);
int /*<<< orphan*/ write_reg(int, int);
void command_adc(char *params) {
  for (const char *p = params; *p; p = skipstring(p)) {
    write_reg(1, 1 | 4);
    write_reg(1, 1);
    if (streq(p, "reset")) {
      write_reg(1, 1 | 8);
      write_reg(1, 1);
      continue;
    }
    unsigned v = hextou(p);
    for (int i = 32768; i; i >>= 1) {
      write_reg(1, (v & i ? 2 : 0) | 4);
      write_reg(1, v & i ? 2 : 0);
    }
  }
  write_reg(1, 1 | 4);
  write_reg(1, 1);
}


x86 assembly (clang, -O0):
<command_adc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1235 <command_adc+0xf5>
mov    $0x1,%edi
mov    $0x5,%esi
call   1040 <write_reg@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <write_reg@plt>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <streq@plt>
cmp    $0x0,%rax
je     11b6 <command_adc+0x76>
mov    $0x1,%edi
mov    $0x9,%esi
call   1040 <write_reg@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <write_reg@plt>
jmp    1223 <command_adc+0xe3>
mov    -0x10(%rbp),%rdi
call   1060 <hextou@plt>
mov    %eax,-0x14(%rbp)
movl   $0x8000,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     121e <command_adc+0xde>
mov    -0x14(%rbp),%ecx
and    -0x18(%rbp),%ecx
xor    %esi,%esi
mov    $0x2,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
or     $0x4,%esi
mov    $0x1,%edi
call   1040 <write_reg@plt>
mov    -0x14(%rbp),%ecx
and    -0x18(%rbp),%ecx
xor    %esi,%esi
mov    $0x2,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
mov    $0x1,%edi
call   1040 <write_reg@plt>
mov    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c9 <command_adc+0x89>
jmp    1223 <command_adc+0xe3>
mov    -0x10(%rbp),%rdi
call   1030 <skipstring@plt>
mov    %rax,-0x10(%rbp)
jmp    1154 <command_adc+0x14>
mov    $0x1,%edi
mov    $0x5,%esi
call   1040 <write_reg@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <write_reg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_adc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1218 <command_adc+0xd8>
mov    %rdi,%r15
lea    0xea2(%rip),%r14
jmp    1192 <command_adc+0x52>
mov    $0x1,%edi
mov    $0x9,%esi
call   1040 <write_reg@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <write_reg@plt>
mov    %r15,%rdi
call   1030 <skipstring@plt>
mov    %rax,%r15
cmpb   $0x0,(%rax)
je     1218 <command_adc+0xd8>
mov    $0x1,%edi
mov    $0x5,%esi
call   1040 <write_reg@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <write_reg@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <streq@plt>
test   %rax,%rax
jne    1160 <command_adc+0x20>
mov    %r15,%rdi
call   1060 <hextou@plt>
mov    %eax,%r12d
mov    $0x8000,%r13d
mov    $0x8000,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
test   %r12d,%r13d
setne  %al
lea    (%rax,%rax,1),%esi
add    $0x4,%esi
mov    %eax,%ebx
add    %eax,%ebx
mov    $0x1,%edi
call   1040 <write_reg@plt>
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <write_reg@plt>
shr    %ebp
cmp    $0x1,%r13d
mov    %ebp,%r13d
ja     11e0 <command_adc+0xa0>
jmp    117e <command_adc+0x3e>
mov    $0x1,%edi
mov    $0x5,%esi
call   1040 <write_reg@plt>
mov    $0x1,%edi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <write_reg@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"reset\00"
define void @command_adc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %46, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %49
11: ; preds = %7
%12 = call i32 @write_reg(i32 1, i32 5)
%13 = call i32 @write_reg(i32 1, i32 1)
%14 = load i8*, i8** %3
%15 = call i64 @streq(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 @write_reg(i32 1, i32 9)
%19 = call i32 @write_reg(i32 1, i32 1)
br label %46
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = call i32 @hextou(i8* %21)
store i32 %22, i32* %4
store i32 32768, i32* %5
br label %23
23: ; preds = %42, %20
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 2, i32 0
%33 = or i32 %32, 4
%34 = call i32 @write_reg(i32 1, i32 %33)
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = and i32 %35, %36
%38 = icmp ne i32 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 2, i32 0
%41 = call i32 @write_reg(i32 1, i32 %40)
br label %42
42: ; preds = %26
%43 = load i32, i32* %5
%44 = ashr i32 %43, 1
store i32 %44, i32* %5
br label %23
45: ; preds = %23
br label %46
46: ; preds = %45, %17
%47 = load i8*, i8** %3
%48 = call i8* @skipstring(i8* %47)
store i8* %48, i8** %3
br label %7
49: ; preds = %7
%50 = call i32 @write_reg(i32 1, i32 5)
%51 = call i32 @write_reg(i32 1, i32 1)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"reset\00"
define void @command_adc(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %28, %1
%5 = tail call i32 @write_reg(i32 1, i32 5)
%6 = tail call i32 @write_reg(i32 1, i32 1)
ret void
7: ; preds = %1, %28
%8 = phi i8* [ %29, %28 ], [ %0, %1 ]
%9 = tail call i32 @write_reg(i32 1, i32 5)
%10 = tail call i32 @write_reg(i32 1, i32 1)
%11 = tail call i64 @streq(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = tail call i32 @write_reg(i32 1, i32 9)
%15 = tail call i32 @write_reg(i32 1, i32 1)
br label %28
16: ; preds = %7
%17 = tail call i32 @hextou(i8* %8)
br label %18
18: ; preds = %16, %18
%19 = phi i32 [ 32768, %16 ], [ %26, %18 ]
%20 = and i32 %19, %17
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 0, i32 2
%23 = or i32 %22, 4
%24 = tail call i32 @write_reg(i32 1, i32 %23)
%25 = tail call i32 @write_reg(i32 1, i32 %22)
%26 = lshr i32 %19, 1
%27 = icmp ult i32 %19, 2
br i1 %27, label %28, label %18
28: ; preds = %18, %13
%29 = tail call i8* @skipstring(i8* %8)
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %4, label %7
}