#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, value;
  if (argc != 3) {
    printf("usage: %s <reg_addr> <reg_value>. sample: %s 0x2010 0x0927\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;
  }
  if (StrToNumber(argv[2], &reg_value)) {
    return 0;
  }
  value = (((reg_addr & 0xffff) << 16) | (reg_value & 0xffff));
  ret = ioctl(fd, 0X3, &value);
  printf("ssp_write %#x, %#x\n", reg_addr, reg_value);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x3,-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    1272 <main+0x122>
lea    0xe96(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d4 <main+0x84>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <main+0x122>
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    1272 <main+0x122>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <StrToNumber@plt>
cmp    $0x0,%rax
je     1222 <main+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    1272 <main+0x122>
mov    -0x1c(%rbp),%eax
and    $0xffff,%eax
shl    $0x10,%eax
mov    -0x20(%rbp),%ecx
and    $0xffff,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
lea    -0x24(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdff(%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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11ff <main+0x9f>
lea    0xec1(%rip),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     1215 <main+0xb5>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1080 <StrToNumber@plt>
test   %rax,%rax
jne    1226 <main+0xc6>
mov    0x10(%rbx),%rdi
lea    0x4(%rsp),%rsi
call   1080 <StrToNumber@plt>
test   %rax,%rax
jne    1226 <main+0xc6>
mov    0x8(%rsp),%eax
shl    $0x10,%eax
movzwl 0x4(%rsp),%ecx
or     %eax,%ecx
mov    %ecx,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x3,%esi
call   1050 <ioctl@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe59(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
jmp    1226 <main+0xc6>
mov    (%rbx),%rdx
lea    0xdf7(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1221 <main+0xc1>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"usage: %s <reg_addr> <reg_value>. sample: %s 0x2010 0x0927\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_write %#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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %19)
store i32 -1, i32* %3
br label %55
21: ; preds = %2
%22 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = 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 %55
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @StrToNumber(i8* %30, i32* %8)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 0, i32* %3
br label %55
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i64 @StrToNumber(i8* %37, i32* %9)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 0, i32* %3
br label %55
41: ; preds = %34
%42 = load i32, i32* %8
%43 = and i32 %42, 65535
%44 = shl i32 %43, 16
%45 = load i32, i32* %9
%46 = and i32 %45, 65535
%47 = or i32 %44, %46
store i32 %47, i32* %10
%48 = load i32, i32* %6
%49 = call i32 @ioctl(i32 %48, i32 3, i32* %10)
store i32 %49, i32* %7
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51)
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
store i32 0, i32* %3
br label %55
55: ; preds = %41, %40, %33, %25, %13
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [60 x i8] c"usage: %s <reg_addr> <reg_value>. sample: %s 0x2010 0x0927\0A\00"
@.str.1 = [9 x i8] c"/dev/ssp\00"
@.str.3 = [20 x i8] c"ssp_write %#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 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %11)
br label %39
13: ; preds = %2
%14 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %39
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @StrToNumber(i8* %20, i32* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @StrToNumber(i8* %25, i32* %4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %23
%29 = load i32, i32* %3
%30 = shl i32 %29, 16
%31 = load i32, i32* %4
%32 = and i32 %31, 65535
%33 = or i32 %32, %30
store i32 %33, i32* %5
%34 = call i32 @ioctl(i32 %14, i32 3, i32* %5)
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36)
%38 = call i32 @close(i32 %14)
br label %39
39: ; preds = %23, %18, %28, %16, %10
%40 = phi i32 [ -1, %10 ], [ -1, %16 ], [ 0, %28 ], [ 0, %18 ], [ 0, %23 ]
ret i32 %40
}