#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*/ O_RDWR;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, unsigned char *, int);
scalar_t__ strcmp(char *, char *);
unsigned char strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char **argv) {
  int fd;
  unsigned char buf[2];
  if ((argc != 3) && (argc != 4)) {
    print_usage(argv[0]);
    return -1;
  }
  fd = open("/dev/at24cxx", O_RDWR);
  if (fd < 0) {
    printf("can't open /dev/at24cxx\n");
    return -1;
  }
  if (strcmp(argv[1], "r") == 0) {
    buf[0] = strtoul(argv[2], NULL, 0);
    read(fd, buf, 1);
    printf("data: %c, %d, 0x%2x\n", buf[0], buf[0], buf[0]);
  } else if (strcmp(argv[1], "w") == 0) {
    buf[0] = strtoul(argv[2], NULL, 0);
    buf[1] = strtoul(argv[3], NULL, 0);
    write(fd, buf, 2);
  } else {
    print_usage(argv[0]);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b2 <main+0x42>
cmpl   $0x4,-0x8(%rbp)
je     11b2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <main+0x166>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ee <main+0x7e>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <main+0x166>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1252 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %al,-0x16(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
movzbl -0x16(%rbp),%esi
movzbl -0x16(%rbp),%edx
movzbl -0x16(%rbp),%ecx
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12cf <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddc(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12b2 <main+0x142>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %al,-0x16(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    12ca <main+0x15a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <main+0x166>
jmp    12cf <main+0x15f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
add    $0xfffffffb,%edi
cmp    $0xfffffffd,%edi
jbe    11d9 <main+0x59>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11e4 <main+0x64>
mov    %eax,%r14d
mov    0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0x80>
mov    0x8(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     123e <main+0xbe>
mov    0x0(%rbp),%rdi
call   10a0 <print_usage@plt>
jmp    11f0 <main+0x70>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x10(%rbp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %al,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
movzbl 0xe(%rsp),%ecx
lea    0xdd1(%rip),%rdi
mov    %ecx,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f5 <main+0x75>
mov    0x10(%rbp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %al,0xe(%rsp)
mov    0x18(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtoul@plt>
mov    %al,0xf(%rsp)
lea    0xe(%rsp),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
call   1040 <write@plt>
jmp    11f5 <main+0x75>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/at24cxx\00"
@O_RDWR = global i32 0
@.str.1 = [25 x i8] c"can't open /dev/at24cxx\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"data: %c, %d, 0x%2x\0A\00"
@.str.4 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @print_usage(i8* %16)
store i32 -1, i32* %3
br label %77
18: ; preds = %10, %2
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %77
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %50
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call zeroext i8 @strtoul(i8* %34, i32* null, i32 0)
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 %35, i8* %36
%37 = load i32, i32* %6
%38 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 1)
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %45, i32 %48)
br label %76
50: ; preds = %25
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %70
56: ; preds = %50
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call zeroext i8 @strtoul(i8* %59, i32* null, i32 0)
%61 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 %60, i8* %61
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 3
%64 = load i8*, i8** %63
%65 = call zeroext i8 @strtoul(i8* %64, i32* null, i32 0)
%66 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 %65, i8* %66
%67 = load i32, i32* %6
%68 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%69 = call i32 @write(i32 %67, i8* %68, i32 2)
br label %75
70: ; preds = %50
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = call i32 @print_usage(i8* %73)
store i32 -1, i32* %3
br label %77
75: ; preds = %56
br label %76
76: ; preds = %75, %31
store i32 0, i32* %3
br label %77
77: ; preds = %76, %70, %23, %13
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/at24cxx\00"
@O_RDWR = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"data: %c, %d, 0x%2x\0A\00"
@.str.4 = [2 x i8] c"w\00"
@str = [24 x i8] c"can't open /dev/at24cxx\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @print_usage(i8* %8)
br label %45
10: ; preds = %2
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %45
16: ; preds = %10
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call zeroext i8 @strtoul(i8* nocapture %23, i32* null, i32 0)
store i8 %24, i8* %4
%25 = call i32 @read(i32 %12, i8* %4, i32 1)
%26 = load i8, i8* %4
%27 = zext i8 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %27, i32 %27)
br label %45
29: ; preds = %16
%30 = load i8*, i8** %17
%31 = tail call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call zeroext i8 @strtoul(i8* nocapture %35, i32* null, i32 0)
store i8 %36, i8* %4
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = tail call zeroext i8 @strtoul(i8* nocapture %38, i32* null, i32 0)
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %39, i8* %40
%41 = call i32 @write(i32 %12, i8* %4, i32 2)
br label %45
42: ; preds = %29
%43 = load i8*, i8** %1
%44 = tail call i32 @print_usage(i8* %43)
br label %45
45: ; preds = %21, %33, %42, %14, %7
%46 = phi i32 [ -1, %7 ], [ -1, %14 ], [ -1, %42 ], [ 0, %33 ], [ 0, %21 ]
ret i32 %46
}