#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ ri2c(int, int, int *);
int strtol(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ wi2c(int, int, int);
int main(int argc, char const *argv[]) {
  if (argc > 1) {
    uint8_t addr = strtol(argv[1], NULL, 16);
    uint16_t reg = strtol(argv[2], NULL, 16);
    printf("0x%02x 0x%04x\n", addr, reg);
    reg = (((reg & 0xff) << 8) & 0xff00) | (((0xff00 & reg) >> 8) & 0xff);
    uint8_t buf = 0;
    if (argc == 4) {
      uint8_t value = strtol(argv[3], NULL, 16);
      wi2c(addr, reg, value);
    }
    ri2c(addr, reg, &buf);
    printf("read-->0x%02x\n", buf);
  } else {
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    122a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
shl    $0x8,%eax
and    $0xff00,%eax
mov    -0x18(%rbp),%ecx
and    $0xff00,%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1205 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <wi2c@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1060 <ri2c@plt>
mov    -0x1c(%rbp),%esi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122f <main+0xef>
jmp    122f <main+0xef>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jl     11f4 <main+0xb4>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%r14d
mov    0x10(%r12),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%ebx
lea    0xe79(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
rol    $0x8,%bx
movzwl %bx,%r15d
movl   $0x0,0xc(%rsp)
cmp    $0x4,%ebp
jne    11c6 <main+0x86>
mov    0x18(%r12),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %eax,%edx
call   1050 <wi2c@plt>
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    %r15d,%esi
call   1060 <ri2c@plt>
mov    0xc(%rsp),%esi
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [15 x i8] c"0x%02x 0x%04x\0A\00"
@.str.1 = [15 x i8] c"read-->0x%02x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %50
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strtol(i8* %15, i32* null, i32 16)
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @strtol(i8* %19, i32* null, i32 16)
store i32 %20, i32* %7
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %7
%25 = and i32 %24, 255
%26 = shl i32 %25, 8
%27 = and i32 %26, 65280
%28 = load i32, i32* %7
%29 = and i32 65280, %28
%30 = ashr i32 %29, 8
%31 = and i32 %30, 255
%32 = or i32 %27, %31
store i32 %32, i32* %7
store i32 0, i32* %8
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 4
br i1 %34, label %35, label %44
35: ; preds = %12
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @strtol(i8* %38, i32* null, i32 16)
store i32 %39, i32* %9
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = load i32, i32* %9
%43 = call i32 @wi2c(i32 %40, i32 %41, i32 %42)
br label %44
44: ; preds = %35, %12
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = call i32 @ri2c(i32 %45, i32 %46, i32* %8)
%48 = load i32, i32* %8
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %48)
br label %51
50: ; preds = %2
br label %51
51: ; preds = %50, %44
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"0x%02x 0x%04x\0A\00"
@.str.1 = [15 x i8] c"read-->0x%02x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @strtol(i8* nocapture %7, i32* null, i32 16)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @strtol(i8* nocapture %10, i32* null, i32 16)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
%13 = trunc i32 %11 to i16
%14 = tail call i16 @llvm.bswap.i16(i16 %13)
%15 = zext i16 %14 to i32
%16 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%17 = icmp eq i32 %0, 4
br i1 %17, label %18, label %23
18: ; preds = %5
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 @strtol(i8* nocapture %20, i32* null, i32 16)
%22 = tail call i32 @wi2c(i32 %8, i32 %15, i32 %21)
br label %23
23: ; preds = %18, %5
%24 = call i32 @ri2c(i32 %8, i32 %15, i32* %3)
%25 = load i32, i32* %3
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %2, %23
ret i32 0
}