#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_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ read(int, void *, int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned char *);
int /*<<< orphan*/ write(int, void *, int);
int main(int argc, char *argv[]) {
  int fdr, fdw, i;
  fdr = open("/dev/xillybus_read_8", O_RDONLY);
  fdw = open("/dev/xillybus_write_8", O_WRONLY);
  if ((fdr < 0) || (fdw < 0)) {
    perror("Failed to open Xillybus device file(s)");
    exit(1);
  }
  unsigned char data_w[] = {50, 150, 170};
  unsigned char data_r[30];
  sscanf(argv[1], "%d", data_w);
  sscanf(argv[2], "%d", &data_w[1]);
  write(fdw, (void *)data_w, 3);
  read(fdr, (void *)data_r, 2);
  data_r[19] = 0;
  for (i = 0; i < 3; i++)
    printf("%d ", data_w[i]);
  for (i = 0; i < 2; i++)
    printf("%d ", data_r[i]);
  close(fdr);
  close(fdw);
  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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11da <main+0x5a>
cmpl   $0x0,-0x18(%rbp)
jge    11f0 <main+0x70>
lea    0xe4a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0xe62(%rip),%ax
mov    %ax,-0x1f(%rbp)
mov    0xe5a(%rip),%al
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1f(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x1f(%rbp),%rdx
add    $0x1,%rdx
lea    0xe1f(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x18(%rbp),%edi
lea    -0x1f(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
movb   $0x0,-0x2d(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1292 <main+0x112>
movslq -0x1c(%rbp),%rax
lea    0xddb(%rip),%rdi
movzbl -0x1f(%rbp,%rax,1),%esi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1265 <main+0xe5>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    12c6 <main+0x146>
movslq -0x1c(%rbp),%rax
lea    0xda7(%rip),%rdi
movzbl -0x40(%rbp,%rax,1),%esi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1299 <main+0x119>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r15d
or     %r14d,%eax
js     1289 <main+0x109>
movb   $0xaa,0xe(%rsp)
movw   $0x9632,0xc(%rsp)
mov    0x8(%rbx),%rdi
lea    0xe73(%rip),%rbp
lea    0xc(%rsp),%r12
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0xd(%rsp),%rdx
mov    %rbp,%rsi
call   1070 <sscanf@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
call   1060 <read@plt>
movzbl 0xc(%rsp),%esi
lea    0xe27(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
movzbl 0xd(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movzbl 0xe(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movzbl 0x10(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movzbl 0x11(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"/dev/xillybus_read_8\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"/dev/xillybus_write_8\00"
@O_WRONLY = global i32 0
@.str.2 = [39 x i8] c"Failed to open Xillybus device file(s)\00"
@__const.main.data_w = [3 x i8] c"2\96\AA"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"%d \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 [3 x i8]
%10 = alloca [30 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17, %2
%21 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = bitcast [3 x i8]* %9 to i8*
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%29 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
%34 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %7
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%37 = call i32 @write(i32 %35, i8* %36, i32 3)
%38 = load i32, i32* %6
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 2)
%41 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 19
store i8 0, i8* %41
store i32 0, i32* %8
br label %42
42: ; preds = %51, %23
%43 = load i32, i32* %8
%44 = icmp slt i32 %43, 3
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %49)
br label %51
51: ; preds = %45
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %42
54: ; preds = %42
store i32 0, i32* %8
br label %55
55: ; preds = %64, %54
%56 = load i32, i32* %8
%57 = icmp slt i32 %56, 2
br i1 %57, label %58, label %67
58: ; preds = %55
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %62)
br label %64
64: ; preds = %58
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %55
67: ; preds = %55
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* %7
%71 = call i32 @close(i32 %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"/dev/xillybus_read_8\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"/dev/xillybus_write_8\00"
@O_WRONLY = global i32 0
@.str.2 = [39 x i8] c"Failed to open Xillybus device file(s)\00"
@__const.main.data_w = [3 x i8] c"2\96\AA"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8]
%4 = alloca [30 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = or i32 %8, %6
%10 = icmp sgt i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = call i32 @write(i32 %8, i8* %15, i32 3)
%25 = call i32 @read(i32 %6, i8* %16, i32 2)
%26 = load i8, i8* %15
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %26)
%28 = load i8, i8* %22
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %28)
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %31)
%33 = load i8, i8* %16
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %33)
%35 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 1
%36 = load i8, i8* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %36)
%38 = call i32 @close(i32 %6)
%39 = call i32 @close(i32 %8)
ret i32 0
}