#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 */
int EXIT_FAILURE;
int /*<<< orphan*/ e_debug_init(int);
int /*<<< orphan*/ e_debug_read(unsigned int, unsigned int *);
int /*<<< orphan*/ e_debug_write(unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  unsigned int dstaddr, data, srcaddr, command, ctrlmode, datamode, write;
  unsigned int rdata;
  int ret;
  if (argc < 2) {
    usage();
    return EXIT_FAILURE;
  } else {
    sscanf(argv[1], "%x_%x_%x_%x", &srcaddr, &data, &dstaddr, &command);
  }
  write = command & 0x01;
  ctrlmode = (command & 0xF8) >> 3;
  datamode = (command & 0x06) >> 1;
  e_debug_init(0x1);
  if (write) {
    e_debug_write(dstaddr, data);
  } else {
    e_debug_read(dstaddr, &rdata);
    printf("[%08x]=0x%08x\n", dstaddr, rdata);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x38>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe59(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x20(%rbp),%r9
call   1050 <sscanf@plt>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
and    $0xf8,%eax
shr    $0x3,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    $0x6,%eax
shr    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
call   1080 <e_debug_init@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1203 <main+0xa3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <e_debug_write@plt>
jmp    1221 <main+0xc1>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1070 <e_debug_read@plt>
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jg     117c <main+0x1c>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
jmp    11e2 <main+0x82>
mov    0x8(%rsi),%rdi
lea    0xe79(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x14(%rsp),%r9
call   1050 <sscanf@plt>
mov    0x14(%rsp),%bl
mov    $0x1,%edi
call   1080 <e_debug_init@plt>
mov    0xc(%rsp),%edi
test   $0x1,%bl
jne    11d7 <main+0x77>
lea    0x10(%rsp),%rsi
call   1070 <e_debug_read@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
jmp    11e0 <main+0x80>
mov    0x18(%rsp),%esi
call   1030 <e_debug_write@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"%x_%x_%x_%x\00"
@.str.1 = [15 x i8] c"[%08x]=0x%08x\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
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (...) @usage()
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %47
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %7, i32* %6, i32* %9)
br label %25
25: ; preds = %20
%26 = load i32, i32* %9
%27 = and i32 %26, 1
store i32 %27, i32* %12
%28 = load i32, i32* %9
%29 = and i32 %28, 248
%30 = lshr i32 %29, 3
store i32 %30, i32* %10
%31 = load i32, i32* %9
%32 = and i32 %31, 6
%33 = lshr i32 %32, 1
store i32 %33, i32* %11
%34 = call i32 @e_debug_init(i32 1)
%35 = load i32, i32* %12
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = call i32 @e_debug_write(i32 %38, i32 %39)
br label %47
41: ; preds = %25
%42 = load i32, i32* %6
%43 = call i32 @e_debug_read(i32 %42, i32* %13)
%44 = load i32, i32* %6
%45 = load i32, i32* %13
%46 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
br label %47
47: ; preds = %17, %41, %37
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [12 x i8] c"%x_%x_%x_%x\00"
@.str.1 = [15 x i8] c"[%08x]=0x%08x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = tail call i32 (...) @usage()
%16 = load i32, i32* @EXIT_FAILURE
br label %34
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %4, i32* %3, i32* %6)
%21 = load i32, i32* %6
%22 = and i32 %21, 1
%23 = call i32 @e_debug_init(i32 1)
%24 = icmp eq i32 %22, 0
%25 = load i32, i32* %3
br i1 %24, label %29, label %26
26: ; preds = %17
%27 = load i32, i32* %4
%28 = call i32 @e_debug_write(i32 %25, i32 %27)
br label %34
29: ; preds = %17
%30 = call i32 @e_debug_read(i32 %25, i32* %7)
%31 = load i32, i32* %3
%32 = load i32, i32* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %26, %29, %14
%35 = phi i32 [ %16, %14 ], [ 0, %29 ], [ 0, %26 ]
ret i32 %35
}