#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*/ O_RDWR;
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int, unsigned long *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scan_i2c_bus(int);
int test(void) {
  int device;
  unsigned long funcs;
  printf("opening device...");
  if ((device = open("/dev/i2c-0", O_RDWR)) < 0) {
    perror("open() failed");
    exit(1);
  }
  printf(" OK\n");
  if (ioctl(device, 0x0705, &funcs) < 0) {
    perror("ioctl() I2C_FUNCS failed");
    exit(1);
  }
  if (funcs & 0x00000001)
    printf("I2C\n");
  if (funcs & ((0x00020000 | 0x00040000)))
    printf("I2C_FUNC_SMBUS_BYTE\n");
  scan_i2c_bus(device);
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11ab <test+0x4b>
lea    0xe81(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x705,%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11e8 <test+0x88>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1206 <test+0xa6>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
and    $0x60000,%rax
cmp    $0x0,%rax
je     1226 <test+0xc6>
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1080 <scan_i2c_bus@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11fa <test+0x8a>
mov    %eax,%ebx
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x705,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
js     1203 <test+0x93>
mov    0x8(%rsp),%rax
test   $0x1,%al
je     11d8 <test+0x68>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rax
test   $0x60000,%eax
je     11eb <test+0x7b>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1090 <scan_i2c_bus@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe1c(%rip),%rdi
jmp    120a <test+0x9a>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"opening device...\00"
@.str.1 = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.2 = [14 x i8] c"open() failed\00"
@.str.3 = [5 x i8] c" OK\0A\00"
@.str.4 = [25 x i8] c"ioctl() I2C_FUNCS failed\00"
@.str.5 = [5 x i8] c"I2C\0A\00"
@.str.6 = [21 x i8] c"I2C_FUNC_SMBUS_BYTE\0A\00"
define i32 @test() {
%1 = alloca i32
%2 = alloca i64
%3 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = call i64 @ioctl(i32 %12, i32 1797, i64* %2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = load i64, i64* %2
%20 = and i64 %19, 1
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i64, i64* %2
%26 = and i64 %25, 393216
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* %1
%32 = call i32 @scan_i2c_bus(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"opening device...\00"
@.str.1 = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.2 = [14 x i8] c"open() failed\00"
@.str.4 = [25 x i8] c"ioctl() I2C_FUNCS failed\00"
@str = [4 x i8] c" OK\00"
@str.7 = [20 x i8] c"I2C_FUNC_SMBUS_BYTE\00"
@str.8 = [4 x i8] c"I2C\00"
define i32 @test() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%12 = call i64 @ioctl(i32 %5, i32 1797, i64* %1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = load i64, i64* %1
%19 = and i64 %18, 1
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0))
%23 = load i64, i64* %1
br label %24
24: ; preds = %21, %17
%25 = phi i64 [ %23, %21 ], [ %18, %17 ]
%26 = and i64 %25, 393216
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = call i32 @scan_i2c_bus(i32 %5)
ret i32 0
}