#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 ADAU1701_Read_register(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int scan_bus() {
  int i = 0;
  int n = 0;
  int ret;
  printf("\n**** Scan for I2C devices ****");
  for (i = 0; i < 256; i++) {
    ret = ADAU1701_Read_register(i, 0);
    if (ret > -1) {
      n++;
      printf("\n Device found at address : 0x%X", i);
    }
  }
  if (i == 0) {
    printf("\n No device found ");
  }
  printf("\n**** End of Scan for I2C devices ****\n");
  return n;
}


x86 assembly (clang, -O0):
<scan_bus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x100,-0x4(%rbp)
jge    119c <scan_bus+0x7c>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <ADAU1701_Read_register@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jle    1189 <scan_bus+0x69>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118e <scan_bus+0x6e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114b <scan_bus+0x2b>
cmpl   $0x0,-0x4(%rbp)
jne    11b4 <scan_bus+0x94>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_bus>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed7(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    115b <scan_bus+0x2b>
nop
add    $0x1,%ebp
cmp    $0x100,%ebp
je     1179 <scan_bus+0x49>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <ADAU1701_Read_register@plt>
test   %eax,%eax
js     1150 <scan_bus+0x20>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1150 <scan_bus+0x20>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0A**** Scan for I2C devices ****\00"
@.str.1 = [33 x i8] c"\0A Device found at address : 0x%X\00"
@.str.2 = [19 x i8] c"\0A No device found \00"
@.str.3 = [40 x i8] c"\0A**** End of Scan for I2C devices ****\0A\00"
define i32 @scan_bus() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 256
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i32, i32* %1
%10 = call i32 @ADAU1701_Read_register(i32 %9, i32 0)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = load i32, i32* %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %13, %8
br label %19
19: ; preds = %18
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
br label %5
22: ; preds = %5
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [32 x i8] c"\0A**** Scan for I2C devices ****\00"
@.str.1 = [33 x i8] c"\0A Device found at address : 0x%X\00"
@str = [39 x i8] c"\0A**** End of Scan for I2C devices ****\00"
define i32 @scan_bus() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %0, %10
%3 = phi i32 [ 0, %0 ], [ %12, %10 ]
%4 = phi i32 [ 0, %0 ], [ %11, %10 ]
%5 = tail call i32 @ADAU1701_Read_register(i32 %3, i32 0)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = add nsw i32 %4, 1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %3)
br label %10
10: ; preds = %2, %7
%11 = phi i32 [ %8, %7 ], [ %4, %2 ]
%12 = add nuw nsw i32 %3, 1
%13 = icmp eq i32 %12, 256
br i1 %13, label %14, label %2
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
ret i32 %11
}