#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 write(int, unsigned char *, int);
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);
  }
  buffer[0] = 0;
  if (write(file, buffer, 1) != 1) {
    printf("error: %s\n", strerror(errno));
    exit(1);
  }
  if (read(file, buffer, len) != len) {
    printf("error : %s\n", strerror(errno));
    exit(1);
  }
  close(file);
  int i, j;
  printf("DATA :");
  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     11e5 <main+0x65>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1227 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    $0x50,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    125f <main+0xdf>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rsi
movb   $0x0,(%rsi)
mov    -0x14(%rbp),%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     12a5 <main+0x125>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1070 <read@plt>
cmp    -0x18(%rbp),%eax
je     12e6 <main+0x166>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1359 <main+0x1d9>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1331 <main+0x1b1>
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1303 <main+0x183>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1040 <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    1293 <main+0xf3>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     12ab <main+0x10b>
mov    %eax,%ebx
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x50,%edx
call   1070 <ioctl@plt>
test   %rax,%rax
js     12b8 <main+0x118>
movb   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x1,%eax
jne    12ce <main+0x12e>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x100,%edx
call   1090 <read@plt>
cmp    $0x100,%eax
jne    12e5 <main+0x145>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe10(%rip),%r14
xor    %ebx,%ebx
jmp    126b <main+0xcb>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
je     127c <main+0xdc>
test   $0xf,%bl
jne    1250 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1250 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd66(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xd63(%rip),%rdi
jmp    12fd <main+0x15d>
lea    0xd99(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd51(%rip),%rdi
jmp    12fa <main+0x15a>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd45(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <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 = [11 x i8] c"error: %s\0A\00"
@errno = global i32 0
@.str.4 = [12 x i8] c"error : %s\0A\00"
@.str.5 = [7 x i8] c"DATA :\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [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 = getelementptr inbounds i8, i8* %15, i64 0
store i8 0, i8* %43
%44 = load i32, i32* %6
%45 = call i32 @write(i32 %44, i8* %15, i32 1)
%46 = icmp ne i32 %45, 1
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = call i32 @read(i32 %53, i8* %15, i32 %54)
%56 = load i32, i32* %7
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %63
58: ; preds = %52
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %52
%64 = load i32, i32* %6
%65 = call i32 @close(i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %10
br label %67
67: ; preds = %84, %63
%68 = load i32, i32* %10
%69 = load i32, i32* %7
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %87
71: ; preds = %67
%72 = load i32, i32* %10
%73 = srem i32 %72, 16
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %71
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
%78 = load i32, i32* %10
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %15, i64 %79
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %82)
br label %84
84: ; preds = %77
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
br label %67
87: ; preds = %67
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
%89 = load i8*, i8** %8
%90 = load i32, i32* %3
ret i32 %90
}

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 = [11 x i8] c"error: %s\0A\00"
@errno = global i32 0
@.str.4 = [12 x i8] c"error : %s\0A\00"
@.str.5 = [7 x i8] c"DATA :\00"
@.str.7 = [6 x i8] c"%02X \00"
@str = [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, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %19
store i8 0, i8* %4
%27 = call i32 @write(i32 %13, i8* %4, i32 1)
%28 = icmp eq i32 %27, 1
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 ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = call i32 @read(i32 %13, i8* %4, i32 256)
%36 = icmp eq i32 %35, 256
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = load i32, i32* @errno
%39 = tail call i8* @strerror(i32 %38)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = tail call i32 @close(i32 %13)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %42, %51
%46 = phi i64 [ 0, %42 ], [ %56, %51 ]
%47 = and i64 %46, 15
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @putchar(i32 10)
br label %51
51: ; preds = %49, %45
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %46
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %54)
%56 = add nuw nsw i64 %46, 1
%57 = icmp eq i64 %56, 256
br i1 %57, label %58, label %45
58: ; preds = %51
%59 = tail call i32 @putchar(i32 10)
ret i32 0
}