#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ I2C_SLAVE_FORCE;
int O_CREAT;
int /*<<< orphan*/ O_RDWR;
int O_TRUNC;
int O_WRONLY;
scalar_t__ dump_eeprom(int, int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ioctl(int, int /*<<< orphan*/, int);
int open(char *, int, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  int i2c_fd, out_fd;
  char *filename = "/dev/i2c-1";
  char *out_file = "eeprom.out";
  int addr = 0x50;
  int rc;
  i2c_fd = open(filename, O_RDWR);
  if (i2c_fd < 0) {
    fprintf(stderr, "Failed to open i2c device %d/%d/%s\n", i2c_fd, errno,
            strerror(errno));
    return EXIT_FAILURE;
  }
  rc = ioctl(i2c_fd, I2C_SLAVE_FORCE, addr);
  if (rc < 0) {
    fprintf(stderr, "Failed to claim i2c device %d/%d/%s\n", rc, errno,
            strerror(errno));
    return EXIT_FAILURE;
  }
  if (argc >= 2)
    out_file = argv[1];
  out_fd = open(out_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  if (out_fd < 0) {
    fprintf(stderr, "Failed to open out device %s %d/%d/%s\n", out_file, rc,
            errno, strerror(errno));
    return EXIT_FAILURE;
  }
  if (dump_eeprom(i2c_fd, out_fd) != 0) {
    unlink(out_file);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x50,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120b <main+0xab>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    %rax,%r8
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x210>
mov    -0x14(%rbp),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edx
call   1050 <ioctl@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1283 <main+0x123>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    %rax,%r8
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x210>
cmpl   $0x2,-0x8(%rbp)
jl     1299 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
mov    0x2d4b(%rip),%rax
or     (%rax),%esi
mov    0x2d3a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1335 <main+0x1d5>
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    %rax,%r9
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x210>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <dump_eeprom@plt>
cmp    $0x0,%rax
je     1364 <main+0x204>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x210>
mov    0x2c3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11b0 <main+0x50>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x50,%edx
call   1050 <ioctl@plt>
mov    %eax,%r15d
test   %eax,%eax
js     11d8 <main+0x78>
cmp    $0x2,%ebp
jl     120e <main+0xae>
mov    0x8(%r14),%r14
jmp    1215 <main+0xb5>
mov    0x2e09(%rip),%rax
mov    (%rax),%r14d
mov    0x2df7(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe45(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
jmp    11fd <main+0x9d>
mov    0x2de1(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd0(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe42(%rip),%rsi
mov    %ebx,%edi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1290 <main+0x130>
lea    0xdf6(%rip),%r14
mov    0x2d7c(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dc2(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     125b <main+0xfb>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <dump_eeprom@plt>
test   %rax,%rax
je     12a4 <main+0x144>
mov    %r14,%rdi
call   1030 <unlink@plt>
jmp    1290 <main+0x130>
mov    0x2d5e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xde4(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cfd(%rip),%rax
jmp    1297 <main+0x137>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [11 x i8] c"eeprom.out\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [36 x i8] c"Failed to open i2c device %d/%d/%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@I2C_SLAVE_FORCE = global i32 0
@.str.3 = [37 x i8] c"Failed to claim i2c device %d/%d/%s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [39 x i8] c"Failed to open out device %s %d/%d/%s\0A\00"
@EXIT_SUCCESS = global i32 0
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 i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %9
store i32 80, i32* %10
%12 = load i8*, i8** %8
%13 = load i32, i32* @O_RDWR
%14 = call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i32, i32* %6
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20, i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %3
br label %77
25: ; preds = %2
%26 = load i32, i32* %6
%27 = load i32, i32* @I2C_SLAVE_FORCE
%28 = load i32, i32* %10
%29 = call i32 @ioctl(i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i32, i32* %11
%35 = load i32, i32* @errno
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %77
40: ; preds = %25
%41 = load i32, i32* %4
%42 = icmp sge i32 %41, 2
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
store i8* %46, i8** %9
br label %47
47: ; preds = %43, %40
%48 = load i8*, i8** %9
%49 = load i32, i32* @O_WRONLY
%50 = load i32, i32* @O_CREAT
%51 = or i32 %49, %50
%52 = load i32, i32* @O_TRUNC
%53 = or i32 %51, %52
%54 = call i32 (i8*, i32, ...) @open(i8* %48, i32 %53, i32 420)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %47
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %9
%60 = load i32, i32* %11
%61 = load i32, i32* @errno
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %59, i32 %60, i32 %61, i8* %63)
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %3
br label %77
66: ; preds = %47
%67 = load i32, i32* %6
%68 = load i32, i32* %7
%69 = call i64 @dump_eeprom(i32 %67, i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %66
%72 = load i8*, i8** %9
%73 = call i32 @unlink(i8* %72)
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
br label %77
75: ; preds = %66
%76 = load i32, i32* @EXIT_SUCCESS
store i32 %76, i32* %3
br label %77
77: ; preds = %75, %71, %57, %32, %17
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [11 x i8] c"eeprom.out\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [36 x i8] c"Failed to open i2c device %d/%d/%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@I2C_SLAVE_FORCE = global i32 0
@.str.3 = [37 x i8] c"Failed to claim i2c device %d/%d/%s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [39 x i8] c"Failed to open out device %s %d/%d/%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %8, i8* %9)
br label %44
11: ; preds = %2
%12 = load i32, i32* @I2C_SLAVE_FORCE
%13 = tail call i32 @ioctl(i32 %4, i32 %12, i32 80)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %17, i8* %18)
br label %44
20: ; preds = %11
%21 = icmp sgt i32 %0, 1
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
br label %25
25: ; preds = %22, %20
%26 = phi i8* [ %24, %22 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %20 ]
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %28, %27
%30 = load i32, i32* @O_TRUNC
%31 = or i32 %29, %30
%32 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %31, i32 420)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %26, i32 %13, i32 %36, i8* %37)
br label %44
39: ; preds = %25
%40 = tail call i64 @dump_eeprom(i32 %4, i32 %32)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = tail call i32 @unlink(i8* %26)
br label %44
44: ; preds = %39, %42, %34, %15, %6
%45 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_FAILURE, %42 ], [ @EXIT_SUCCESS, %39 ]
%46 = load i32, i32* %45
ret i32 %46
}