#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 /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int write(int, char *, int);
int main() {
  int fp;
  char w_buf1[11] = "U201414815";
  char w_buf2[11] = "abcdefg";
  char r_buf1[50];
  char r_buf2[20];
  if ((fp = open("/dev/mydev0", O_RDWR)) == -1) {
    perror("fopen");
    exit(1);
  }
  if ((write(fp, w_buf1, 10)) == -1) {
    perror("write");
    exit(1);
  }
  if ((write(fp, w_buf2, 11)) == -1) {
    perror("write");
    exit(1);
  }
  if ((read(fp, r_buf1, 10)) == -1) {
    perror("read");
    exit(1);
  }
  if ((read(fp, r_buf2, 2)) == -1) {
    perror("read");
    exit(1);
  }
  r_buf1[10] = '\0';
  printf("%s\n", r_buf1);
  r_buf2[2] = '\0';
  printf("%s\n", r_buf2);
  close(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x13(%rbp)
mov    0xe77(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xe6f(%rip),%al
mov    %al,-0x9(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x1e(%rbp)
mov    0xe84(%rip),%ax
mov    %ax,-0x16(%rbp)
mov    0xe7c(%rip),%al
mov    %al,-0x14(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11f4 <main+0x84>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1224 <main+0xb4>
lea    0xe08(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1254 <main+0xe4>
lea    0xdd8(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    1284 <main+0x114>
lea    0xdae(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    12b4 <main+0x144>
lea    0xd7e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movb   $0x0,-0x46(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xd65(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0x6e(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xd51(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
movabs $0x3834313431303255,%rax
31 34 38
mov    %rax,0x10(%rsp)
movl   $0x353138,0x17(%rsp)
movabs $0x67666564636261,%rax
mov    %rax,(%rsp)
movl   $0x0,0x7(%rsp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1268 <main+0xf8>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1256 <main+0xe6>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1256 <main+0xe6>
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     125f <main+0xef>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     125f <main+0xef>
movb   $0x0,0x4a(%rsp)
lea    0xe02(%rip),%r14
lea    0x40(%rsp),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
movb   $0x0,0x22(%rsp)
lea    0x20(%rsp),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdc0(%rip),%rdi
jmp    126f <main+0xff>
lea    0xdbd(%rip),%rdi
jmp    126f <main+0xff>
lea    0xda8(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.w_buf1 = [11 x i8] c"U201414815\00"
@__const.main.w_buf2 = [11 x i8] c"abcdefg\00\00\00\00"
@.str = [12 x i8] c"/dev/mydev0\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"fopen\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [11 x i8]
%4 = alloca [11 x i8]
%5 = alloca [50 x i8]
%6 = alloca [20 x i8]
store i32 0, i32* %1
%7 = bitcast [11 x i8]* %3 to i8*
%8 = bitcast [11 x i8]* %4 to i8*
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* %2
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 10)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = load i32, i32* %2
%25 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%26 = call i32 @write(i32 %24, i8* %25, i32 11)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load i32, i32* %2
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 10)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i32, i32* %2
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 2)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
%48 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 10
store i8 0, i8* %48
%49 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 2
store i8 0, i8* %51
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %2
%55 = call i32 @close(i32 %54)
ret i32 0
}

LLVM IR (-O2):
@__const.main.w_buf1 = [11 x i8] c"U201414815\00"
@__const.main.w_buf2 = [11 x i8] c"abcdefg\00\00\00\00"
@.str = [12 x i8] c"/dev/mydev0\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"fopen\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = alloca [11 x i8]
%3 = alloca [50 x i8]
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @write(i32 %10, i8* %5, i32 10)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @write(i32 %10, i8* %6, i32 11)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %21
%28 = call i32 @read(i32 %10, i8* %7, i32 10)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %27
%34 = call i32 @read(i32 %10, i8* %8, i32 2)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %33
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 10
store i8 0, i8* %40
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 2
store i8 0, i8* %42
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%44 = call i32 @close(i32 %10)
ret i32 0
}