#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 /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  int fd = -1;
  int tt[3] = {0};
  char xx[3] = {0};
  fd = open("/dev/cxn010x", O_RDWR);
  if (fd == -1) {
    printf("Failed to open device %s\n", "/dev/cxn010x");
    return -1;
  }
  read(fd, xx, 3);
  printf("read value %d,%d,%d\n", xx[0], xx[1], xx[2]);
  tt[0] = 2;
  tt[1] = 1;
  write(fd, tt, 2);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
lea    -0x23(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1050 <memset@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e0 <main+0x80>
lea    0xe47(%rip),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    -0x14(%rbp),%edi
lea    -0x23(%rbp),%rsi
mov    $0x3,%edx
call   1070 <read@plt>
movsbl -0x23(%rbp),%esi
movsbl -0x22(%rbp),%edx
movsbl -0x21(%rbp),%ecx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x14(%rsp)
movb   $0x0,0xa(%rsp)
movw   $0x0,0x8(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11df <main+0x8f>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1060 <read@plt>
movsbl 0x8(%rsp),%esi
movsbl 0x9(%rsp),%edx
movsbl 0xa(%rsp),%ecx
lea    0xe7a(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
movabs $0x100000002,%rax
mov    %rax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    11f9 <main+0xa9>
lea    0xe27(%rip),%rdi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/cxn010x\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"Failed to open device %s\0A\00"
@.str.2 = [21 x i8] c"read value %d,%d,%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca [3 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%9 = bitcast [3 x i32]* %7 to i8*
%10 = bitcast [3 x i8]* %8 to i8*
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
17: ; preds = %2
%18 = load i32, i32* %6
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 3)
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %26, i32 %29)
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
store i32 2, i32* %31
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
store i32 1, i32* %32
%33 = load i32, i32* %6
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%35 = call i32 @write(i32 %33, i32* %34, i32 2)
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %17, %15
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/cxn010x\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"Failed to open device %s\0A\00"
@.str.2 = [21 x i8] c"read value %d,%d,%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32]
%4 = alloca [3 x i8]
%5 = bitcast [3 x i32]* %3 to i8*
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
store i32 0, i32* %6
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %28
13: ; preds = %2
%14 = call i32 @read(i32 %9, i8* %7, i32 3)
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %19, i32 %22)
%24 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
store i32 2, i32* %24
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
store i32 1, i32* %25
%26 = call i32 @write(i32 %9, i32* %24, i32 2)
%27 = tail call i32 @close(i32 %9)
br label %28
28: ; preds = %13, %11
%29 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %29
}