#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 */
typedef int uint8_t;
typedef int uint64_t;

/* Variables and functions */
int mmio_read(char *, int);
int /*<<< orphan*/ printf(char *);
uint64_t query_i2c_readdata_val(char resource_file[]) {
  uint64_t offset = 0x0000000000000130;
  int rv;
  uint64_t read_data;
  uint8_t i2c_rdata = 0x00;
  read_data = mmio_read(resource_file, offset);
  i2c_rdata = ((read_data & 0x000000000000FF00) >> 8);
  if ((read_data & 0x4000000000000000) == 0x4000000000000000) {
    printf("I2C controller read data is valid\n");
    return read_data;
  } else
    return 1;
}


x86 assembly (clang, -O0):
<query_i2c_readdata_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x130,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <mmio_read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
movabs $0x4000000000000000,%rcx
and    %rcx,%rax
movabs $0x4000000000000000,%rcx
cmp    %rcx,%rax
jne    1192 <query_i2c_readdata_val+0x72>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <query_i2c_readdata_val+0x79>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_i2c_readdata_val>:
push   %rbx
mov    $0x130,%esi
call   1040 <mmio_read@plt>
mov    %eax,%ebx
movslq %eax,%rcx
mov    $0x1,%eax
bt     $0x3e,%rcx
jae    114a <query_i2c_readdata_val+0x2a>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"I2C controller read data is valid\0A\00"
define i32 @query_i2c_readdata_val(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 304, i32* %4
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i32 @mmio_read(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = and i32 %11, 65280
%13 = ashr i32 %12, 8
store i32 %13, i32* %7
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = and i64 %15, 4611686018427387904
%17 = icmp eq i64 %16, 4611686018427387904
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %6
store i32 %20, i32* %2
br label %22
21: ; preds = %1
store i32 1, i32* %2
br label %22
22: ; preds = %21, %18
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@str = [34 x i8] c"I2C controller read data is valid\00"
define i32 @query_i2c_readdata_val(i8* %0) {
%2 = tail call i32 @mmio_read(i8* %0, i32 304)
%3 = sext i32 %2 to i64
%4 = and i64 %3, 4611686018427387904
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %1, %6
%9 = phi i32 [ %2, %6 ], [ 1, %1 ]
ret i32 %9
}