#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*/ hex_to_nes(unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ hex_to_nes6(unsigned int, unsigned int);
int /*<<< orphan*/ nes_to_hex(char *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  unsigned int address, data, compare;
  if (argc == 4) {
    sscanf(argv[1], "0x%x", &address);
    sscanf(argv[2], "0x%x", &data);
    sscanf(argv[3], "0x%x", &compare);
    hex_to_nes(address, data, compare);
  } else if (argc == 3) {
    sscanf(argv[1], "0x%x", &address);
    sscanf(argv[2], "0x%x", &data);
    hex_to_nes6(address, data);
  } else if (argc == 2) {
    nes_to_hex(argv[1]);
  } else {
    usage(argv[0]);
  }
  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   $0x4,-0x8(%rbp)
jne    11cb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe69(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe51(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <hex_to_nes@plt>
jmp    1247 <main+0xf7>
cmpl   $0x3,-0x8(%rbp)
jne    1215 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe04(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <hex_to_nes6@plt>
jmp    1242 <main+0xf2>
cmpl   $0x2,-0x8(%rbp)
jne    1231 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <nes_to_hex@plt>
jmp    123d <main+0xed>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
jmp    1242 <main+0xf2>
jmp    1247 <main+0xf7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11ba <main+0x6a>
cmp    $0x3,%edi
je     11c5 <main+0x75>
cmp    $0x4,%edi
jne    11fd <main+0xad>
mov    0x8(%rbx),%rdi
lea    0xe88(%rip),%r14
lea    0x10(%rsp),%rdx
mov    %r14,%rsi
call   1050 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0xc(%rsp),%rdx
mov    %r14,%rsi
call   1050 <sscanf@plt>
mov    0x18(%rbx),%rdi
lea    0x14(%rsp),%rdx
mov    %r14,%rsi
call   1050 <sscanf@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%edx
call   1070 <hex_to_nes@plt>
jmp    1205 <main+0xb5>
mov    0x8(%rbx),%rdi
call   1040 <nes_to_hex@plt>
jmp    1205 <main+0xb5>
mov    0x8(%rbx),%rdi
lea    0xe30(%rip),%r14
lea    0x10(%rsp),%rdx
mov    %r14,%rsi
call   1050 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0xc(%rsp),%rdx
mov    %r14,%rsi
call   1050 <sscanf@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
call   1030 <hex_to_nes6@plt>
jmp    1205 <main+0xb5>
mov    (%rbx),%rdi
call   1060 <usage@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0x%x\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %7)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %8)
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @hex_to_nes(i32 %24, i32 %25, i32 %26)
br label %58
28: ; preds = %2
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %7)
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = call i32 @hex_to_nes6(i32 %40, i32 %41)
br label %57
43: ; preds = %28
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 2
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @nes_to_hex(i8* %49)
br label %56
51: ; preds = %43
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @usage(i8* %54)
br label %56
56: ; preds = %51, %46
br label %57
57: ; preds = %56, %31
br label %58
58: ; preds = %57, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"0x%x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
switch i32 %0, label %37 [
i32 4, label %9
i32 3, label %23
i32 2, label %33
]
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4)
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5)
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i32 @hex_to_nes(i32 %19, i32 %20, i32 %21)
br label %40
23: ; preds = %2
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4)
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @hex_to_nes6(i32 %30, i32 %31)
br label %40
33: ; preds = %2
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call i32 @nes_to_hex(i8* %35)
br label %40
37: ; preds = %2
%38 = load i8*, i8** %1
%39 = tail call i32 @usage(i8* %38)
br label %40
40: ; preds = %23, %37, %33, %9
ret i32 0
}