#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__ EBUSY;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int i2c_smbus_read_byte(int);
int i2c_smbus_write_quick(int, int /*<<< orphan*/);
scalar_t__ ioctl(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int scan_i2c_bus(int file, const int mode, const int first, const int last) {
  int i, j;
  int res;
  printf("     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n");
  for (i = 0; i < 128; i += 16) {
    printf("%02x: ", i);
    for (j = 0; j < 16; j++) {
      if (i + j < first || i + j > last) {
        printf("   ");
        continue;
      }
      if (ioctl(file, 0x0703, i + j) < 0) {
        if (errno == EBUSY) {
          printf("UU ");
          continue;
        } else {
          fprintf(stderr,
                  "Error: Could not set "
                  "address to 0x%02x: %s\n",
                  i + j, strerror(errno));
          return -1;
        }
      }
      switch (mode) {
      case 1:
        res = i2c_smbus_write_quick(file, 0);
        break;
      case 2:
        res = i2c_smbus_read_byte(file);
        break;
      default:
        if ((i + j >= 0x30 && i + j <= 0x37) ||
            (i + j >= 0x50 && i + j <= 0x5F))
          res = i2c_smbus_read_byte(file);
        else
          res = i2c_smbus_write_quick(file, 0);
      }
      if (res < 0)
        printf("XX ");
      else
        printf("%02x ", i + j);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_i2c_bus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x80,-0x18(%rbp)
jge    137d <scan_i2c_bus+0x21d>
mov    -0x18(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1361 <scan_i2c_bus+0x201>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     11d6 <scan_i2c_bus+0x76>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11e9 <scan_i2c_bus+0x89>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1353 <scan_i2c_bus+0x1f3>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%edx
add    -0x1c(%rbp),%edx
mov    $0x703,%esi
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1278 <scan_i2c_bus+0x118>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
jne    1233 <scan_i2c_bus+0xd3>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1353 <scan_i2c_bus+0x1f3>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xddd(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1384 <scan_i2c_bus+0x224>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     129d <scan_i2c_bus+0x13d>
jmp    128c <scan_i2c_bus+0x12c>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     12af <scan_i2c_bus+0x14f>
jmp    12bf <scan_i2c_bus+0x15f>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1070 <i2c_smbus_write_quick@plt>
mov    %eax,-0x20(%rbp)
jmp    131d <scan_i2c_bus+0x1bd>
mov    -0x8(%rbp),%edi
call   1060 <i2c_smbus_read_byte@plt>
mov    %eax,-0x20(%rbp)
jmp    131d <scan_i2c_bus+0x1bd>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    $0x30,%eax
jl     12dd <scan_i2c_bus+0x17d>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    $0x37,%eax
jle    12fb <scan_i2c_bus+0x19b>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    $0x50,%eax
jl     130b <scan_i2c_bus+0x1ab>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    $0x5f,%eax
jg     130b <scan_i2c_bus+0x1ab>
mov    -0x8(%rbp),%edi
call   1060 <i2c_smbus_read_byte@plt>
mov    %eax,-0x20(%rbp)
jmp    1318 <scan_i2c_bus+0x1b8>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1070 <i2c_smbus_write_quick@plt>
mov    %eax,-0x20(%rbp)
jmp    131d <scan_i2c_bus+0x1bd>
cmpl   $0x0,-0x20(%rbp)
jge    133a <scan_i2c_bus+0x1da>
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    134e <scan_i2c_bus+0x1ee>
mov    -0x18(%rbp),%esi
add    -0x1c(%rbp),%esi
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1353 <scan_i2c_bus+0x1f3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <scan_i2c_bus+0x4e>
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <scan_i2c_bus+0x29>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_i2c_bus>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,0x4(%rsp)
mov    %edi,%ebx
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
xor    %r12d,%r12d
jmp    11cc <scan_i2c_bus+0x4c>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x10(%r12),%eax
cmp    $0x70,%r12d
mov    %eax,%r12d
jae    12e1 <scan_i2c_bus+0x161>
lea    0xe2d(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %r14d,%r14d
jmp    1208 <scan_i2c_bus+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14d
cmp    $0x10,%r14d
je     11b0 <scan_i2c_bus+0x30>
lea    (%r12,%r14,1),%r13d
cmp    %ebp,%r13d
jl     11f0 <scan_i2c_bus+0x70>
cmp    %r15d,%r13d
jg     11f0 <scan_i2c_bus+0x70>
mov    %ebx,%edi
mov    $0x703,%esi
mov    %r13d,%edx
call   1060 <ioctl@plt>
test   %rax,%rax
js     1272 <scan_i2c_bus+0xf2>
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
je     1294 <scan_i2c_bus+0x114>
cmp    $0x1,%eax
je     1252 <scan_i2c_bus+0xd2>
mov    %r13d,%eax
and    $0x7ffffff8,%eax
cmp    $0x30,%eax
je     1294 <scan_i2c_bus+0x114>
mov    %r13d,%eax
and    $0x7ffffff0,%eax
cmp    $0x50,%eax
je     1294 <scan_i2c_bus+0x114>
mov    %ebx,%edi
xor    %esi,%esi
call   1090 <i2c_smbus_write_quick@plt>
test   %eax,%eax
js     129f <scan_i2c_bus+0x11f>
lea    0xdd9(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11fe <scan_i2c_bus+0x7e>
mov    0x2d5f(%rip),%rax
mov    (%rax),%rdi
mov    0x2d4d(%rip),%rax
cmp    (%rax),%rdi
jne    12ab <scan_i2c_bus+0x12b>
lea    0xd7c(%rip),%rdi
jmp    11f7 <scan_i2c_bus+0x77>
mov    %ebx,%edi
call   1080 <i2c_smbus_read_byte@plt>
test   %eax,%eax
jns    125f <scan_i2c_bus+0xdf>
lea    0xd95(%rip),%rdi
jmp    11f7 <scan_i2c_bus+0x77>
mov    0x2d2e(%rip),%rax
mov    (%rax),%ebx
call   10a0 <strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebx,%edi
mov    %r13d,%edx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    12d2 <scan_i2c_bus+0x152>

LLVM IR (-O0):
@.str = [53 x i8] c" 0 1 2 3 4 5 6 7 8 9 a b c d e f\0A\00"
@.str.1 = [7 x i8] c"%02x: \00"
@.str.2 = [4 x i8] c" \00"
@errno = global i64 0
@EBUSY = global i64 0
@.str.3 = [4 x i8] c"UU \00"
@stderr = global i32 0
@.str.4 = [44 x i8] c"Error: Could not set address to 0x%02x: %s\0A\00"
@.str.5 = [4 x i8] c"XX \00"
@.str.6 = [6 x i8] c"%02x \00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @scan_i2c_bus(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
br label %14
14: ; preds = %109, %4
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 128
br i1 %16, label %17, label %112
17: ; preds = %14
%18 = load i32, i32* %10
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i32 0, i32* %11
br label %20
20: ; preds = %104, %17
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 16
br i1 %22, label %23, label %107
23: ; preds = %20
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = add nsw i32 %24, %25
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %35, label %29
29: ; preds = %23
%30 = load i32, i32* %10
%31 = load i32, i32* %11
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %9
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %29, %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %104
37: ; preds = %29
%38 = load i32, i32* %6
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = add nsw i32 %39, %40
%42 = call i64 @ioctl(i32 %38, i32 1795, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %58
44: ; preds = %37
%45 = load i64, i64* @errno
%46 = load i64, i64* @EBUSY
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %104
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i32, i32* %10
%53 = load i32, i32* %11
%54 = add nsw i32 %52, %53
%55 = load i64, i64* @errno
%56 = call i8* @strerror(i64 %55)
%57 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %54, i8* %56)
store i32 -1, i32* %5
br label %113
58: ; preds = %37
%59 = load i32, i32* %7
switch i32 %59, label %66 [
i32 1, label %60
i32 2, label %63
]
60: ; preds = %58
%61 = load i32, i32* %6
%62 = call i32 @i2c_smbus_write_quick(i32 %61, i32 0)
store i32 %62, i32* %12
br label %93
63: ; preds = %58
%64 = load i32, i32* %6
%65 = call i32 @i2c_smbus_read_byte(i32 %64)
store i32 %65, i32* %12
br label %93
66: ; preds = %58
%67 = load i32, i32* %10
%68 = load i32, i32* %11
%69 = add nsw i32 %67, %68
%70 = icmp sge i32 %69, 48
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i32, i32* %10
%73 = load i32, i32* %11
%74 = add nsw i32 %72, %73
%75 = icmp sle i32 %74, 55
br i1 %75, label %86, label %76
76: ; preds = %71, %66
%77 = load i32, i32* %10
%78 = load i32, i32* %11
%79 = add nsw i32 %77, %78
%80 = icmp sge i32 %79, 80
br i1 %80, label %81, label %89
81: ; preds = %76
%82 = load i32, i32* %10
%83 = load i32, i32* %11
%84 = add nsw i32 %82, %83
%85 = icmp sle i32 %84, 95
br i1 %85, label %86, label %89
86: ; preds = %81, %71
%87 = load i32, i32* %6
%88 = call i32 @i2c_smbus_read_byte(i32 %87)
store i32 %88, i32* %12
br label %92
89: ; preds = %81, %76
%90 = load i32, i32* %6
%91 = call i32 @i2c_smbus_write_quick(i32 %90, i32 0)
store i32 %91, i32* %12
br label %92
92: ; preds = %89, %86
br label %93
93: ; preds = %92, %63, %60
%94 = load i32, i32* %12
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %103
98: ; preds = %93
%99 = load i32, i32* %10
%100 = load i32, i32* %11
%101 = add nsw i32 %99, %100
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %101)
br label %103
103: ; preds = %98, %96
br label %104
104: ; preds = %103, %48, %35
%105 = load i32, i32* %11
%106 = add nsw i32 %105, 1
store i32 %106, i32* %11
br label %20
107: ; preds = %20
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %109
109: ; preds = %107
%110 = load i32, i32* %10
%111 = add nsw i32 %110, 16
store i32 %111, i32* %10
br label %14
112: ; preds = %14
store i32 0, i32* %5
br label %113
113: ; preds = %112, %50
%114 = load i32, i32* %5
ret i32 %114
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%02x: \00"
@.str.2 = [4 x i8] c" \00"
@errno = global i64 0
@EBUSY = global i64 0
@.str.3 = [4 x i8] c"UU \00"
@stderr = global i32 0
@.str.4 = [44 x i8] c"Error: Could not set address to 0x%02x: %s\0A\00"
@.str.5 = [4 x i8] c"XX \00"
@.str.6 = [6 x i8] c"%02x \00"
@str = [52 x i8] c" 0 1 2 3 4 5 6 7 8 9 a b c d e f\00"
define i32 @scan_i2c_bus(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %55
%7 = phi i32 [ 0, %4 ], [ %57, %55 ]
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %6, %52
%10 = phi i32 [ 0, %6 ], [ %53, %52 ]
%11 = add nuw nsw i32 %10, %7
%12 = icmp slt i32 %11, %2
%13 = icmp sgt i32 %11, %3
%14 = or i1 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %52
17: ; preds = %9
%18 = tail call i64 @ioctl(i32 %0, i32 1795, i32 %11)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = load i64, i64* @EBUSY
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %52
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = tail call i8* @strerror(i64 %21)
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %11, i8* %28)
br label %59
30: ; preds = %17
switch i32 %1, label %35 [
i32 1, label %31
i32 2, label %33
]
31: ; preds = %30
%32 = tail call i32 @i2c_smbus_write_quick(i32 %0, i32 0)
br label %45
33: ; preds = %30
%34 = tail call i32 @i2c_smbus_read_byte(i32 %0)
br label %45
35: ; preds = %30
%36 = and i32 %11, 2147483640
%37 = icmp eq i32 %36, 48
%38 = and i32 %11, 2147483632
%39 = icmp eq i32 %38, 80
%40 = or i1 %37, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = tail call i32 @i2c_smbus_read_byte(i32 %0)
br label %45
43: ; preds = %35
%44 = tail call i32 @i2c_smbus_write_quick(i32 %0, i32 0)
br label %45
45: ; preds = %41, %43, %33, %31
%46 = phi i32 [ %42, %41 ], [ %44, %43 ], [ %34, %33 ], [ %32, %31 ]
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %52
50: ; preds = %45
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %11)
br label %52
52: ; preds = %48, %50, %24, %15
%53 = add nuw nsw i32 %10, 1
%54 = icmp eq i32 %53, 16
br i1 %54, label %55, label %9
55: ; preds = %52
%56 = tail call i32 @putchar(i32 10)
%57 = add nuw nsw i32 %7, 16
%58 = icmp ult i32 %7, 112
br i1 %58, label %6, label %59
59: ; preds = %55, %26
%60 = phi i32 [ -1, %26 ], [ 0, %55 ]
ret i32 %60
}