#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 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 = 0;
  unsigned int device_addr, reg_addr, reg_value, value;
  if (argc != 4) {
    printf("usage: %s <device_addr> <reg_addr> <value>. sample: %s 0x56 0x0 "
           "0x28\n",
           argv[0], argv[0]);
    return -1;
  }
  fd = open("/dev/gpioi2c", 0);
  if (fd < 0) {
    printf("Open gpioi2c error!\n");
    return -1;
  }
  if (StrToNumber(argv[1], &device_addr)) {
    return 0;
  }
  if (StrToNumber(argv[2], &reg_addr)) {
    return 0;
  }
  if (StrToNumber(argv[3], &reg_value)) {
    return 0;
  }
  printf("device_addr:0x%2x; reg_addr:0x%2x; reg_value:0x%2x.\n", device_addr,
         reg_addr, reg_value);
  value = ((device_addr & 0xff) << 24) | ((reg_addr & 0xff) << 16) |
          (reg_value & 0xffff);
  ret = ioctl(fd, 0x03, &value);
  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)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1196 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <main+0x159>
lea    0xea9(%rip),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cb <main+0x8b>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1299 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <StrToNumber@plt>
cmp    $0x0,%rax
je     11f2 <main+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    1299 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <StrToNumber@plt>
cmp    $0x0,%rax
je     1219 <main+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    1299 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <StrToNumber@plt>
cmp    $0x0,%rax
je     1240 <main+0x100>
movl   $0x0,-0x4(%rbp)
jmp    1299 <main+0x159>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
shl    $0x18,%eax
mov    -0x20(%rbp),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x24(%rbp),%ecx
and    $0xffff,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
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,%rbp
cmp    $0x4,%edi
jne    120a <main+0xba>
lea    0xedb(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
js     1221 <main+0xd1>
mov    %eax,%r14d
mov    0x8(%rbp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <StrToNumber@plt>
test   %rax,%rax
jne    1232 <main+0xe2>
mov    0x10(%rbp),%rdi
lea    0x4(%rsp),%rsi
call   1070 <StrToNumber@plt>
test   %rax,%rax
jne    1232 <main+0xe2>
mov    0x18(%rbp),%rdi
mov    %rsp,%rsi
call   1070 <StrToNumber@plt>
test   %rax,%rax
jne    1232 <main+0xe2>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
lea    0xe83(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%eax
shl    $0x18,%eax
mov    0x4(%rsp),%ecx
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
movzwl (%rsp),%eax
or     %ecx,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
mov    $0x3,%esi
call   1050 <ioctl@plt>
jmp    1232 <main+0xe2>
mov    0x0(%rbp),%rdx
lea    0xdeb(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122d <main+0xdd>
lea    0xe60(%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 = [70 x i8] c"usage: %s <device_addr> <reg_addr> <value>. sample: %s 0x56 0x0 0x28\0A\00"
@.str.1 = [13 x i8] c"/dev/gpioi2c\00"
@.str.2 = [21 x i8] c"Open gpioi2c error!\0A\00"
@.str.3 = [53 x i8] c"device_addr:0x%2x; reg_addr:0x%2x; reg_value:0x%2x.\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 0, i32* %7
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %20)
store i32 -1, i32* %3
br label %66
22: ; preds = %2
%23 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i64 @StrToNumber(i8* %31, i32* %8)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 0, i32* %3
br label %66
35: ; preds = %28
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i64 @StrToNumber(i8* %38, i32* %9)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
store i32 0, i32* %3
br label %66
42: ; preds = %35
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i64 @StrToNumber(i8* %45, i32* %10)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 0, i32* %3
br label %66
49: ; preds = %42
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = load i32, i32* %10
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51, i32 %52)
%54 = load i32, i32* %8
%55 = and i32 %54, 255
%56 = shl i32 %55, 24
%57 = load i32, i32* %9
%58 = and i32 %57, 255
%59 = shl i32 %58, 16
%60 = or i32 %56, %59
%61 = load i32, i32* %10
%62 = and i32 %61, 65535
%63 = or i32 %60, %62
store i32 %63, i32* %11
%64 = load i32, i32* %6
%65 = call i32 @ioctl(i32 %64, i32 3, i32* %11)
store i32 %65, i32* %7
store i32 0, i32* %3
br label %66
66: ; preds = %49, %48, %41, %34, %26, %14
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [70 x i8] c"usage: %s <device_addr> <reg_addr> <value>. sample: %s 0x56 0x0 0x28\0A\00"
@.str.1 = [13 x i8] c"/dev/gpioi2c\00"
@.str.3 = [53 x i8] c"device_addr:0x%2x; reg_addr:0x%2x; reg_value:0x%2x.\0A\00"
@str = [20 x i8] c"Open gpioi2c error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 4
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %13)
br label %50
15: ; preds = %2
%16 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %50
20: ; preds = %15
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @StrToNumber(i8* %22, i32* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %20
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @StrToNumber(i8* %27, i32* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %25
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = call i64 @StrToNumber(i8* %32, i32* %5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %30
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %3
%41 = shl i32 %40, 24
%42 = load i32, i32* %4
%43 = shl i32 %42, 16
%44 = and i32 %43, 16711680
%45 = or i32 %44, %41
%46 = load i32, i32* %5
%47 = and i32 %46, 65535
%48 = or i32 %45, %47
store i32 %48, i32* %6
%49 = call i32 @ioctl(i32 %16, i32 3, i32* %6)
br label %50
50: ; preds = %30, %25, %20, %35, %18, %12
%51 = phi i32 [ -1, %12 ], [ -1, %18 ], [ 0, %35 ], [ 0, %20 ], [ 0, %25 ], [ 0, %30 ]
ret i32 %51
}