#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 *);
int /*<<< orphan*/ read_registers(unsigned int, int, unsigned char *);
char *skipstring(char const *);
int /*<<< orphan*/ write_reg(unsigned int, unsigned int);
void command_write(char *params) {
  const char *p = params;
  unsigned r = hextou(p);
  p = skipstring(p);
  unsigned v = hextou(p);
  p = skipstring(p);
  if (*p) {
    unsigned mask = hextou(p);
    unsigned char old;
    read_registers(r, 1, &old);
    v = v ^ (old & ~mask);
  }
  write_reg(r, v);
}


x86 assembly (clang, -O0):
<command_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <hextou@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <skipstring@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <hextou@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <skipstring@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c4 <command_write+0x84>
mov    -0x10(%rbp),%rdi
call   1060 <hextou@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
lea    -0x1d(%rbp),%rdx
call   1040 <read_registers@plt>
mov    -0x18(%rbp),%eax
movzbl -0x1d(%rbp),%ecx
mov    -0x1c(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <write_reg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_write>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
call   1060 <hextou@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <skipstring@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <hextou@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <skipstring@plt>
cmpb   $0x0,(%rax)
je     119c <command_write+0x5c>
mov    %rax,%rdi
call   1060 <hextou@plt>
mov    %eax,%ebx
lea    0xf(%rsp),%rdx
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <read_registers@plt>
movzbl 0xf(%rsp),%eax
not    %ebx
and    %eax,%ebx
xor    %ebx,%ebp
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <write_reg@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @command_write(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %2
%8 = load i8*, i8** %2
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @hextou(i8* %9)
store i32 %10, i32* %4
%11 = load i8*, i8** %3
%12 = call i8* @skipstring(i8* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @hextou(i8* %13)
store i32 %14, i32* %5
%15 = load i8*, i8** %3
%16 = call i8* @skipstring(i8* %15)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %1
%21 = load i8*, i8** %3
%22 = call i32 @hextou(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %4
%24 = call i32 @read_registers(i32 %23, i32 1, i8* %7)
%25 = load i32, i32* %5
%26 = load i8, i8* %7
%27 = zext i8 %26 to i32
%28 = load i32, i32* %6
%29 = xor i32 %28, -1
%30 = and i32 %27, %29
%31 = xor i32 %25, %30
store i32 %31, i32* %5
br label %32
32: ; preds = %20, %1
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = call i32 @write_reg(i32 %33, i32 %34)
ret void
}

LLVM IR (-O2):
define void @command_write(i8* %0) {
%2 = alloca i8
%3 = tail call i32 @hextou(i8* %0)
%4 = tail call i8* @skipstring(i8* %0)
%5 = tail call i32 @hextou(i8* %4)
%6 = tail call i8* @skipstring(i8* %4)
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %1
%10 = tail call i32 @hextou(i8* %6)
%11 = call i32 @read_registers(i32 %3, i32 1, i8* %2)
%12 = load i8, i8* %2
%13 = zext i8 %12 to i32
%14 = xor i32 %10, -1
%15 = and i32 %13, %14
%16 = xor i32 %15, %5
br label %17
17: ; preds = %9, %1
%18 = phi i32 [ %16, %9 ], [ %5, %1 ]
%19 = call i32 @write_reg(i32 %3, i32 %18)
ret void
}