#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 /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
int /*<<< orphan*/ regio_rd32(unsigned int, unsigned int *, unsigned int);
int /*<<< orphan*/ regio_wr32(unsigned int, unsigned int, unsigned int);
scalar_t__ strcmp(char *, char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  unsigned int addr;
  unsigned int data;
  unsigned int verbose = 0;
  int argn = 0;
  if (strcmp(argv[1], "-v") == 0) {
    verbose = 1;
    argn = 1;
  }
  if (strcmp(argv[argn + 1], "-r") == 0) {
    addr = strtoul(argv[argn + 2], NULL, 16);
    regio_rd32(addr, &data, verbose);
    printf("R 0x%08x 0x%08x\n", addr, data);
  } else if (strcmp(argv[argn + 1], "-w") == 0) {
    addr = strtoul(argv[argn + 2], NULL, 16);
    data = strtoul(argv[argn + 3], NULL, 16);
    regio_wr32(addr, data, verbose);
    printf("W 0x%08x 0x%08x\n", addr, data);
  }
  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)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a0 <main+0x50>
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe4b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    120f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1040 <regio_rd32@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
jmp    129f <main+0x14f>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    129a <main+0x14a>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <regio_wr32@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xd85(%rip),%rdi
call   1030 <printf@plt>
jmp    129f <main+0x14f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%r15
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    0x8(%r14,%rbx,8),%rdi
lea    0xe82(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f4 <main+0xa4>
lea    0x1(%rbx),%rax
mov    (%r14,%rax,8),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1229 <main+0xd9>
xor    %ebp,%ebp
test   %r15,%r15
sete   %bpl
lea    0x2(%rbx),%eax
mov    (%r14,%rax,8),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,%r15d
mov    0x18(%r14,%rbp,8),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %eax,%esi
mov    %ebx,%edx
call   1070 <regio_wr32@plt>
lea    0xe2d(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
jmp    1224 <main+0xd4>
lea    0x2(%rbx),%eax
mov    (%r14,%rax,8),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebp
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   1040 <regio_rd32@plt>
mov    0x4(%rsp),%edx
lea    0xde4(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-v\00"
@.str.1 = [3 x i8] c"-r\00"
@.str.2 = [17 x i8] c"R 0x%08x 0x%08x\0A\00"
@.str.3 = [3 x i8] c"-w\00"
@.str.4 = [17 x i8] c"W 0x%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %8
store i32 1, i32* %9
br label %16
16: ; preds = %15, %2
%17 = load i8**, i8*** %5
%18 = load i32, i32* %9
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %17, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strtoul(i8* %31, i32* null, i32 16)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = load i32, i32* %8
%35 = call i32 @regio_rd32(i32 %33, i32* %7, i32 %34)
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
br label %71
39: ; preds = %16
%40 = load i8**, i8*** %5
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %70
48: ; preds = %39
%49 = load i8**, i8*** %5
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @strtoul(i8* %54, i32* null, i32 16)
store i32 %55, i32* %6
%56 = load i8**, i8*** %5
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %56, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 @strtoul(i8* %61, i32* null, i32 16)
store i32 %62, i32* %7
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = call i32 @regio_wr32(i32 %63, i32 %64, i32 %65)
%67 = load i32, i32* %6
%68 = load i32, i32* %7
%69 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %67, i32 %68)
br label %70
70: ; preds = %48, %39
br label %71
71: ; preds = %70, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-v\00"
@.str.1 = [3 x i8] c"-r\00"
@.str.2 = [17 x i8] c"R 0x%08x 0x%08x\0A\00"
@.str.3 = [3 x i8] c"-w\00"
@.str.4 = [17 x i8] c"W 0x%08x 0x%08x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = select i1 %8, i64 2, i64 1
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = or i32 %9, 2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @strtoul(i8* nocapture %19, i32* null, i32 16)
%21 = call i32 @regio_rd32(i32 %20, i32* %3, i32 %9)
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %22)
br label %40
24: ; preds = %2
%25 = load i8*, i8** %11
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = or i32 %9, 2
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i32 @strtoul(i8* nocapture %32, i32* null, i32 16)
%34 = select i1 %8, i64 4, i64 3
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32 @strtoul(i8* nocapture %36, i32* null, i32 16)
%38 = tail call i32 @regio_wr32(i32 %33, i32 %37, i32 %9)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %33, i32 %37)
br label %40
40: ; preds = %24, %28, %15
ret i32 0
}