#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*/ _i2c_write_read(unsigned char *, int, unsigned char *,
                                   unsigned int, int);
int /*<<< orphan*/ printf(char *, ...);
void radeon_i2c(void) {
  int i, j;
  unsigned char wbuf[128];
  unsigned char rbuf[128];
  unsigned int rsize = 15;
  for (i = 0; i < 1; i++) {
    wbuf[0] = i * 4;
    _i2c_write_read(wbuf, 1, rbuf, rsize, (1 << 16));
    for (j = 0; j < rsize; j++) {
      printf("%02X", rbuf[j]);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<radeon_i2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0xf,-0x114(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    11c7 <radeon_i2c+0xa7>
mov    -0x4(%rbp),%eax
shl    $0x2,%eax
mov    %al,-0x90(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%rdx
mov    -0x114(%rbp),%ecx
mov    $0x1,%esi
mov    $0x10000,%r8d
call   1030 <_i2c_write_read@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x114(%rbp),%eax
jae    11b4 <radeon_i2c+0x94>
movslq -0x8(%rbp),%rax
movzbl -0x110(%rbp,%rax,1),%esi
ff
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117d <radeon_i2c+0x5d>
jmp    11b9 <radeon_i2c+0x99>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113c <radeon_i2c+0x1c>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<radeon_i2c>:
push   %rbx
sub    $0x100,%rsp
movb   $0x0,0x80(%rsp)
lea    0x80(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x1,%esi
mov    $0xf,%ecx
mov    $0x10000,%r8d
call   1040 <_i2c_write_read@plt>
movzbl (%rsp),%esi
lea    0xe95(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x1(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x2(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x3(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x6(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x7(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xd(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xe(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @radeon_i2c() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i32
store i32 15, i32* %5
store i32 0, i32* %1
br label %6
6: ; preds = %33, %0
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = load i32, i32* %1
%11 = mul nsw i32 %10, 4
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8 %12, i8* %13
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* %5
%17 = call i32 @_i2c_write_read(i8* %14, i32 1, i8* %15, i32 %16, i32 65536)
store i32 0, i32* %2
br label %18
18: ; preds = %29, %9
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %22
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %18
32: ; preds = %18
br label %33
33: ; preds = %32
%34 = load i32, i32* %1
%35 = add nsw i32 %34, 1
store i32 %35, i32* %1
br label %6
36: ; preds = %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @radeon_i2c() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%5 = call i32 @_i2c_write_read(i8* %3, i32 1, i8* %4, i32 15, i32 65536)
%6 = load i8, i8* %4
%7 = zext i8 %6 to i32
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 1
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 3
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 4
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 5
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 6
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 7
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 8
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 9
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 10
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 11
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 12
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 13
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 14
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %63)
%65 = call i32 @putchar(i32 10)
ret void
}