#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*/ ee24c02_write(int, int, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char const *argv[]) {
  int file, i, len;
  unsigned char *ptr;
  if (argc != 3) {
    printf("Usage:\nee24c02w.bin /dev/i2c string");
    fflush(stdout);
    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);
  }
  ee24c02_write(file, 100, (unsigned char *)argv[2], strlen(argv[2]));
  close(file);
  exit(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)
cmpl   $0x3,-0x8(%rbp)
je     11c6 <main+0x46>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1208 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    $0x50,%edx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1240 <main+0xc0>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    $0x64,%esi
call   1030 <ee24c02_write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11cd <main+0x3d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
jns    11f3 <main+0x63>
mov    0x8(%rbx),%rsi
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    $0x50,%edx
call   1070 <ioctl@plt>
test   %rax,%rax
jns    1225 <main+0x95>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    $0x64,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1030 <ee24c02_write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Usage:\0Aee24c02w.bin /dev/i2c string\00"
@stdout = global i32 0
@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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i32, i32* %6
%32 = load i32, i32* @I2C_SLAVE
%33 = call i64 @ioctl(i32 %31, i32 %32, i32 80)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %30
%39 = load i32, i32* %6
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @ee24c02_write(i32 %39, i32 100, i8* %42, i32 %46)
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
%50 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [36 x i8] c"Usage:\0Aee24c02w.bin /dev/i2c string\00"
@stdout = global i32 0
@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 = [25 x i8] c"Cannot init chip address\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%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
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = tail call i32 @strlen(i8* %28)
%30 = tail call i32 @ee24c02_write(i32 %13, i32 100, i8* %28, i32 %29)
%31 = tail call i32 @close(i32 %13)
%32 = tail call i32 @exit(i32 0)
unreachable
}