#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*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  int testdev;
  int i, ret;
  char buf[15];
  testdev = open("/dev/mycdev", O_RDWR);
  if (-1 == testdev) {
    printf("Cannot open file.\n");
    exit(1);
  }
  if (ret = read(testdev, buf, 15) < 15) {
    printf("Read error!\n");
    exit(1);
  }
  printf("%s\n", buf);
  close(testdev);
  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)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    11a4 <main+0x54>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2b(%rbp),%rsi
mov    $0xf,%edx
call   1050 <read@plt>
cmp    $0xf,%eax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x1c(%rbp)
test   $0x1,%al
jne    11d3 <main+0x83>
jmp    11eb <main+0x9b>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x2b(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x50>
mov    %eax,%ebx
lea    0x1(%rsp),%rsi
mov    %eax,%edi
mov    $0xf,%edx
call   1050 <read@plt>
cmp    $0xe,%eax
jle    11a9 <main+0x59>
lea    0x1(%rsp),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe71(%rip),%rdi
jmp    11b0 <main+0x60>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/mycdev\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"Cannot open file.\0A\00"
@.str.2 = [13 x i8] c"Read error!\0A\00"
@.str.3 = [4 x i8] c"%s\0A\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 [15 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %6
%19 = getelementptr inbounds [15 x i8], [15 x i8]* %9, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 15)
%21 = icmp slt i32 %20, 15
%22 = zext i1 %21 to i32
store i32 %22, i32* %8
br i1 %21, label %23, label %26
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = getelementptr inbounds [15 x i8], [15 x i8]* %9, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/mycdev\00"
@O_RDWR = global i32 0
@str = [12 x i8] c"Read error!\00"
@str.4 = [18 x i8] c"Cannot open file.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [15 x i8]
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i32 @read(i32 %6, i8* %4, i32 15)
%13 = icmp slt i32 %12, 15
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = call i32 @puts(i8* %4)
%19 = tail call i32 @close(i32 %6)
ret i32 0
}