#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 */
scalar_t__ StrToNumber(char *, unsigned int *);
int /*<<< orphan*/ close(int);
int ioctl(int, int, unsigned int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int fd = -1;
  int ret;
  unsigned int reg_addr, reg_value;
  if (argc != 2) {
    printf("usage: %s <addr>. sample: %s 0x2010\n", argv[0], argv[0]);
    return -1;
  }
  fd = open("/dev/ssp", 0);
  if (fd < 0) {
    printf("Open /dev/ssp error!\n");
    return -1;
  }
  if (StrToNumber(argv[1], &reg_addr)) {
    return 0;
  }
  reg_value = reg_addr;
  ret = ioctl(fd, 0x1, &reg_value);
  printf("ssp_read %#x = %#x\n", reg_addr, reg_value);
  close(fd);
  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   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <main+0xe8>
lea    0xe7f(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d4 <main+0x84>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <StrToNumber@plt>
cmp    $0x0,%rax
je     11fb <main+0xab>
movl   $0x0,-0x4(%rbp)
jmp    1238 <main+0xe8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    11d6 <main+0x76>
lea    0xeae(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     11ed <main+0x8d>
mov    %eax,%r14d
mov    0x8(%rbp),%rdi
lea    0xc(%rsp),%rsi
call   1080 <StrToNumber@plt>
test   %rax,%rax
jne    11fe <main+0x9e>
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
mov    $0x1,%esi
call   1050 <ioctl@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe6b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
jmp    11fe <main+0x9e>
mov    0x0(%rbp),%rdx
lea    0xe1f(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f9 <main+0x99>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"usage: %s <addr>. sample: %s 0x2010\0A\00"
@.str.1 = [9 x i8] c"/dev/ssp\00"
@.str.2 = [22 x i8] c"Open /dev/ssp error!\0A\00"
@.str.3 = [20 x i8] c"ssp_read %#x = %#x\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 -1, i32* %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %18)
store i32 -1, i32* %3
br label %42
20: ; preds = %2
%21 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @StrToNumber(i8* %29, i32* %8)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 0, i32* %3
br label %42
33: ; preds = %26
%34 = load i32, i32* %8
store i32 %34, i32* %9
%35 = load i32, i32* %6
%36 = call i32 @ioctl(i32 %35, i32 1, i32* %9)
store i32 %36, i32* %7
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %38)
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %33, %32, %24, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [37 x i8] c"usage: %s <addr>. sample: %s 0x2010\0A\00"
@.str.1 = [9 x i8] c"/dev/ssp\00"
@.str.3 = [20 x i8] c"ssp_read %#x = %#x\0A\00"
@str = [21 x i8] c"Open /dev/ssp error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %9)
br label %28
11: ; preds = %2
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %28
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @StrToNumber(i8* %18, i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load i32, i32* %3
store i32 %22, i32* %4
%23 = call i32 @ioctl(i32 %12, i32 1, i32* %4)
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %25)
%27 = call i32 @close(i32 %12)
br label %28
28: ; preds = %16, %21, %14, %8
%29 = phi i32 [ -1, %8 ], [ -1, %14 ], [ 0, %21 ], [ 0, %16 ]
ret i32 %29
}