#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_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
char *strerror(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int file;
  int len = 256;
  unsigned char buffer[len];
  if (argc != 2) {
    printf("Usage:\nedid.bin /dev/i2c");
    exit(1);
  }
  if ((file = open(argv[1], O_RDWR)) < 0) {
    printf("Failed to open the bus %s\n", argv[1]);
    exit(1);
  }
  if (ioctl(file, I2C_SLAVE, 0x50) < 0) {
    printf("Cannot init chip address\n");
    exit(1);
  }
  if (read(file, buffer, len) != len) {
    printf("error : %s\n", strerror(errno));
    exit(1);
  }
  close(file);
  int i, j;
  printf("DATAT :\n");
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0)
      printf("\n");
    printf("%02X ", buffer[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x100,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d5 <main+0x65>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1217 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    $0x50,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    124f <main+0xdf>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1060 <read@plt>
cmp    -0x18(%rbp),%eax
je     1290 <main+0x120>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1303 <main+0x193>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12db <main+0x16b>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ad <main+0x13d>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
cmp    $0x2,%edi
jne    1263 <main+0xd3>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     127b <main+0xeb>
mov    %eax,%ebx
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x50,%edx
call   1060 <ioctl@plt>
test   %rax,%rax
js     1288 <main+0xf8>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x100,%edx
call   1080 <read@plt>
cmp    $0x100,%eax
jne    129e <main+0x10e>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xe3e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2c(%rip),%r14
xor    %ebx,%ebx
jmp    123b <main+0xab>
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
je     124c <main+0xbc>
test   $0xf,%bl
jne    1220 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd96(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xd93(%rip),%rdi
jmp    12b6 <main+0x126>
lea    0xdbf(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd81(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Usage:\0Aedid.bin /dev/i2c\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"Failed to open the bus %s\0A\00"
@I2C_SLAVE = global i32 0
@.str.2 = [26 x i8] c"Cannot init chip address\0A\00"
@.str.3 = [12 x i8] c"error : %s\0A\00"
@errno = global i32 0
@.str.4 = [9 x i8] c"DATAT :\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [6 x i8] c"%02X \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 256, i32* %7
%12 = load i32, i32* %7
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %21
%35 = load i32, i32* %6
%36 = load i32, i32* @I2C_SLAVE
%37 = call i64 @ioctl(i32 %35, i32 %36, i32 80)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = call i32 @read(i32 %43, i8* %15, i32 %44)
%46 = load i32, i32* %7
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = load i32, i32* %6
%55 = call i32 @close(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %10
br label %57
57: ; preds = %74, %53
%58 = load i32, i32* %10
%59 = load i32, i32* %7
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %77
61: ; preds = %57
%62 = load i32, i32* %10
%63 = srem i32 %62, 16
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
%68 = load i32, i32* %10
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %15, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %67
%75 = load i32, i32* %10
%76 = add nsw i32 %75, 1
store i32 %76, i32* %10
br label %57
77: ; preds = %57
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
%79 = load i8*, i8** %8
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@.str = [25 x i8] c"Usage:\0Aedid.bin /dev/i2c\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"Failed to open the bus %s\0A\00"
@I2C_SLAVE = global i32 0
@.str.3 = [12 x i8] c"error : %s\0A\00"
@errno = global i32 0
@.str.6 = [6 x i8] c"%02X \00"
@str = [8 x i8] c"DATAT :\00"
@str.7 = [25 x i8] c"Cannot init chip address\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i8*, i8** %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9
%20 = load i32, i32* @I2C_SLAVE
%21 = tail call i64 @ioctl(i32 %13, i32 %20, i32 80)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = call i32 @read(i32 %13, i8* %4, i32 256)
%28 = icmp eq i32 %27, 256
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = tail call i32 @close(i32 %13)
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %34, %43
%38 = phi i64 [ 0, %34 ], [ %48, %43 ]
%39 = and i64 %38, 15
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i32 @putchar(i32 10)
br label %43
43: ; preds = %41, %37
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %38
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %38, 1
%49 = icmp eq i64 %48, 256
br i1 %49, label %50, label %37
50: ; preds = %43
%51 = tail call i32 @putchar(i32 10)
ret i32 0
}