#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 ENOENT;
int ENOTDIR;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ i2c_probe(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int list_i2c_accessible(int bus) {
  ((void)0);
  int fd, ret = -1;
  char dev_file_name[13];
  bool i2c_bus_found = false;
  int i = (bus < 0) ? 0 : bus;
  int end = (bus < 0) ? 255 : bus;
  for (; i <= end; i++) {
    sprintf(dev_file_name, "/dev/i2c-%d", i);
    fd = open(dev_file_name, O_RDWR);
    if (fd < 0 && (errno == ENOENT || errno == ENOTDIR))
      continue;
    i2c_bus_found = true;
    if (fd < 0) {
      fprintf(stderr, "Failed accessing I2C bus %d: %s (%d)\n", i,
              strerror(errno), -errno);
      continue;
    }
    ret = 0;
    printf("On i2c-%d:\n\t", i);
    for (int j = 0x03; j <= 0x77; j++)
      if (i2c_probe(fd, j))
        printf("0x%x ", j);
    printf("\n");
    close(fd);
  }
  if (!i2c_bus_found) {
    fprintf(stderr, "No "
                    "I2C device"
                    " was found");
    (bus >= 0) ? fprintf(stderr, " on bus %d\n", bus) : fprintf(stderr, "\n");
    fprintf(stderr, "Is "
                    "i2c-dev"
                    " driver loaded?\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<list_i2c_accessible>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    119d <list_i2c_accessible+0x2d>
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
jmp    11a3 <list_i2c_accessible+0x33>
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11c0 <list_i2c_accessible+0x50>
mov    $0xff,%eax
mov    %eax,-0x34(%rbp)
jmp    11c6 <list_i2c_accessible+0x56>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     131f <list_i2c_accessible+0x1af>
lea    -0x19(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe1a(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x19(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    123f <list_i2c_accessible+0xcf>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    0x2d9e(%rip),%rcx
cmp    (%rcx),%eax
je     123a <list_i2c_accessible+0xca>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%eax
jne    123f <list_i2c_accessible+0xcf>
jmp    1311 <list_i2c_accessible+0x1a1>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1299 <list_i2c_accessible+0x129>
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
xor    %r8d,%r8d
mov    0x2d45(%rip),%rax
sub    (%rax),%r8d
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1311 <list_i2c_accessible+0x1a1>
movl   $0x0,-0xc(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x2c(%rbp)
cmpl   $0x77,-0x2c(%rbp)
jg     12fb <list_i2c_accessible+0x18b>
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1040 <i2c_probe@plt>
cmp    $0x0,%rax
je     12e8 <list_i2c_accessible+0x178>
mov    -0x2c(%rbp),%esi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ed <list_i2c_accessible+0x17d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12b8 <list_i2c_accessible+0x148>
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cc <list_i2c_accessible+0x5c>
cmpl   $0x0,-0x20(%rbp)
jne    1397 <list_i2c_accessible+0x227>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpl   $0x0,-0x4(%rbp)
jl     1369 <list_i2c_accessible+0x1f9>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xd00(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1380 <list_i2c_accessible+0x210>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
lea    0xcb7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
lea    0xcd9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_i2c_accessible>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
xor    %eax,%eax
test   %edi,%edi
mov    %edi,%ebx
cmovs  %eax,%ebx
mov    $0xff,%r12d
cmovns %edi,%r12d
mov    $0xffffffff,%r14d
cmp    %r12d,%ebx
ja     12d8 <list_i2c_accessible+0x158>
mov    %ebp,0x4(%rsp)
movl   $0xffffffff,(%rsp)
lea    0xb(%rsp),%r15
lea    0xe76(%rip),%r14
xor    %ebp,%ebp
jmp    11fc <list_i2c_accessible+0x7c>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13d,%edi
call   1060 <close@plt>
movl   $0x0,(%rsp)
mov    $0x1,%ebp
lea    0x1(%rbx),%eax
cmp    %r12d,%ebx
mov    %eax,%ebx
je     12cc <list_i2c_accessible+0x14c>
mov    %r15,%rdi
lea    0xdfa(%rip),%rsi
mov    %ebx,%edx
call   1090 <sprintf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1270 <list_i2c_accessible+0xf0>
mov    %eax,%r13d
lea    0xe06(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%ebp
jmp    1248 <list_i2c_accessible+0xc8>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x78,%ebp
je     11d0 <list_i2c_accessible+0x50>
mov    %r13d,%edi
mov    %ebp,%esi
call   1050 <i2c_probe@plt>
test   %rax,%rax
je     1240 <list_i2c_accessible+0xc0>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1240 <list_i2c_accessible+0xc0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    0x2d38(%rip),%rax
cmp    (%rax),%edi
je     11ee <list_i2c_accessible+0x6e>
mov    0x2d69(%rip),%rax
cmp    (%rax),%edi
je     11ee <list_i2c_accessible+0x6e>
mov    0x2d32(%rip),%rax
mov    (%rax),%ebp
call   10a0 <strerror@plt>
xor    %r8d,%r8d
mov    0x2d19(%rip),%rcx
sub    (%rcx),%r8d
mov    %ebp,%edi
lea    0xd51(%rip),%rsi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11e9 <list_i2c_accessible+0x69>
test   %ebp,%ebp
mov    0x4(%rsp),%ebp
mov    (%rsp),%r14d
jne    1325 <list_i2c_accessible+0x1a5>
mov    0x2cf1(%rip),%rbx
mov    (%rbx),%edi
lea    0xd5d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
test   %ebp,%ebp
js     1307 <list_i2c_accessible+0x187>
lea    0xd61(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1315 <list_i2c_accessible+0x195>
lea    0xd22(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd4b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/i2c-%d\00"
@O_RDWR = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
@ENOTDIR = global i32 0
@stderr = global i32 0
@.str.1 = [38 x i8] c"Failed accessing I2C bus %d: %s (%d)\0A\00"
@.str.2 = [13 x i8] c"On i2c-%d:\0A\09\00"
@.str.3 = [6 x i8] c"0x%x \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [24 x i8] c"No I2C device was found\00"
@.str.6 = [12 x i8] c" on bus %d\0A\00"
@.str.7 = [27 x i8] c"Is i2c-dev driver loaded?\0A\00"
define i32 @list_i2c_accessible(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [13 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %4
store i32 0, i32* %6
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
br label %15
13: ; preds = %1
%14 = load i32, i32* %2
br label %15
15: ; preds = %13, %12
%16 = phi i32 [ 0, %12 ], [ %14, %13 ]
store i32 %16, i32* %7
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %22
20: ; preds = %15
%21 = load i32, i32* %2
br label %22
22: ; preds = %20, %19
%23 = phi i32 [ 255, %19 ], [ %21, %20 ]
store i32 %23, i32* %8
br label %24
24: ; preds = %79, %22
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %82
28: ; preds = %24
%29 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* %7
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* @O_RDWR
%34 = call i32 @open(i8* %32, i32 %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %28
%38 = load i32, i32* @errno
%39 = load i32, i32* @ENOENT
%40 = icmp eq i32 %38, %39
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i32, i32* @errno
%43 = load i32, i32* @ENOTDIR
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41, %37
br label %79
46: ; preds = %41, %28
store i32 1, i32* %6
%47 = load i32, i32* %3
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i32, i32* %7
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = load i32, i32* @errno
%55 = sub nsw i32 0, %54
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %51, i8* %53, i32 %55)
br label %79
57: ; preds = %46
store i32 0, i32* %4
%58 = load i32, i32* %7
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %58)
store i32 3, i32* %9
br label %60
60: ; preds = %72, %57
%61 = load i32, i32* %9
%62 = icmp sle i32 %61, 119
br i1 %62, label %63, label %75
63: ; preds = %60
%64 = load i32, i32* %3
%65 = load i32, i32* %9
%66 = call i64 @i2c_probe(i32 %64, i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* %9
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %68, %63
br label %72
72: ; preds = %71
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %60
75: ; preds = %60
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* %3
%78 = call i32 @close(i32 %77)
br label %79
79: ; preds = %75, %49, %45
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %24
82: ; preds = %24
%83 = load i32, i32* %6
%84 = icmp ne i32 %83, 0
br i1 %84, label %101, label %85
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%88 = load i32, i32* %2
%89 = icmp sge i32 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %85
%91 = load i32, i32* @stderr
%92 = load i32, i32* %2
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %92)
br label %97
94: ; preds = %85
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %97
97: ; preds = %94, %90
%98 = phi i32 [ %93, %90 ], [ %96, %94 ]
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %101
101: ; preds = %97, %82
%102 = load i32, i32* %4
ret i32 %102
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/i2c-%d\00"
@O_RDWR = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
@ENOTDIR = global i32 0
@stderr = global i32 0
@.str.1 = [38 x i8] c"Failed accessing I2C bus %d: %s (%d)\0A\00"
@.str.2 = [13 x i8] c"On i2c-%d:\0A\09\00"
@.str.3 = [6 x i8] c"0x%x \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [24 x i8] c"No I2C device was found\00"
@.str.6 = [12 x i8] c" on bus %d\0A\00"
@.str.7 = [27 x i8] c"Is i2c-dev driver loaded?\0A\00"
define i32 @list_i2c_accessible(i32 %0) {
%2 = alloca [13 x i8]
%3 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
%5 = select i1 %4, i32 0, i32 %0
%6 = select i1 %4, i32 255, i32 %0
%7 = icmp ugt i32 %5, %6
br i1 %7, label %50, label %8
8: ; preds = %1, %43
%9 = phi i32 [ %45, %43 ], [ -1, %1 ]
%10 = phi i32 [ %46, %43 ], [ %5, %1 ]
%11 = phi i32 [ %44, %43 ], [ 0, %1 ]
%12 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %3, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %8
%17 = load i32, i32* @errno
%18 = load i32, i32* @ENOENT
%19 = icmp eq i32 %17, %18
%20 = load i32, i32* @ENOTDIR
%21 = icmp eq i32 %17, %20
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %43, label %23
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = tail call i8* @strerror(i32 %17)
%26 = load i32, i32* @errno
%27 = sub nsw i32 0, %26
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %25, i32 %27)
br label %43
29: ; preds = %8
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %34
31: ; preds = %40
%32 = tail call i32 @putchar(i32 10)
%33 = tail call i32 @close(i32 %14)
br label %43
34: ; preds = %29, %40
%35 = phi i32 [ 3, %29 ], [ %41, %40 ]
%36 = tail call i64 @i2c_probe(i32 %14, i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %40
40: ; preds = %34, %38
%41 = add nuw nsw i32 %35, 1
%42 = icmp eq i32 %41, 120
br i1 %42, label %31, label %34
43: ; preds = %16, %31, %23
%44 = phi i32 [ %11, %16 ], [ 1, %23 ], [ 1, %31 ]
%45 = phi i32 [ %9, %16 ], [ %9, %23 ], [ 0, %31 ]
%46 = add nuw i32 %10, 1
%47 = icmp eq i32 %10, %6
br i1 %47, label %48, label %8
48: ; preds = %43
%49 = icmp eq i32 %44, 0
br i1 %49, label %50, label %63
50: ; preds = %1, %48
%51 = phi i32 [ %45, %48 ], [ -1, %1 ]
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%54 = icmp sgt i32 %0, -1
%55 = load i32, i32* @stderr
br i1 %54, label %56, label %58
56: ; preds = %50
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %0)
br label %60
58: ; preds = %50
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
%61 = load i32, i32* @stderr
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %60, %48
%64 = phi i32 [ %51, %60 ], [ %45, %48 ]
ret i32 %64
}