#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*/ perror(char *);
int read(int, float *, int);
int tdl_read(int fd, float pos[3], float orient[9]) {
  int posSize = 3 * (signed int)sizeof(float);
  int orientSize = 9 * (signed int)sizeof(float);
  int readVal = 0;
  if ((readVal = read(fd, pos, posSize)) < posSize) {
    if (readVal == 0) {
      return 1;
    } else {
      perror("Reading position failed");
      return -1;
    }
  }
  if ((readVal = read(fd, orient, orientSize)) < orientSize) {
    if (readVal == 0) {
      return 1;
    } else {
      perror("Reading position failed");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<tdl_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xc,-0x1c(%rbp)
movl   $0x24,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    -0x1c(%rbp),%eax
jge    1191 <tdl_read+0x71>
cmpl   $0x0,-0x24(%rbp)
jne    1179 <tdl_read+0x59>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <tdl_read+0xc1>
lea    0xe80(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <tdl_read+0xc1>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    -0x20(%rbp),%eax
jge    11da <tdl_read+0xba>
cmpl   $0x0,-0x24(%rbp)
jne    11c2 <tdl_read+0xa2>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <tdl_read+0xc1>
lea    0xe37(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <tdl_read+0xc1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tdl_read>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %edi,%ebp
mov    $0xc,%edx
call   1030 <read@plt>
cmp    $0xb,%eax
jg     113b <tdl_read+0x1b>
mov    %eax,%ecx
jmp    1153 <tdl_read+0x33>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x24,%edx
call   1030 <read@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x23,%ecx
jg     115c <tdl_read+0x3c>
mov    $0x1,%eax
test   %ecx,%ecx
jne    1163 <tdl_read+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    115c <tdl_read+0x3c>

LLVM IR (-O0):
@.str = [24 x i8] c"Reading position failed\00"
define i32 @tdl_read(i32 %0, float* %1, float* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca float*
%7 = alloca float*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store float* %1, float** %6
store float* %2, float** %7
store i32 12, i32* %8
store i32 36, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %5
%12 = load float*, float** %6
%13 = load i32, i32* %8
%14 = call i32 @read(i32 %11, float* %12, i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 1, i32* %4
br label %37
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %37
23: ; preds = %3
%24 = load i32, i32* %5
%25 = load float*, float** %7
%26 = load i32, i32* %9
%27 = call i32 @read(i32 %24, float* %25, i32 %26)
store i32 %27, i32* %10
%28 = load i32, i32* %9
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = load i32, i32* %10
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 1, i32* %4
br label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %37
36: ; preds = %23
store i32 0, i32* %4
br label %37
37: ; preds = %36, %34, %33, %21, %20
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [24 x i8] c"Reading position failed\00"
define i32 @tdl_read(i32 %0, float* nocapture %1, float* nocapture %2) {
%4 = tail call i32 @read(i32 %0, float* %1, i32 12)
%5 = icmp slt i32 %4, 12
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = icmp eq i32 %4, 0
br i1 %7, label %15, label %13
8: ; preds = %3
%9 = tail call i32 @read(i32 %0, float* %2, i32 36)
%10 = icmp slt i32 %9, 36
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = icmp eq i32 %9, 0
br i1 %12, label %15, label %13
13: ; preds = %11, %6
%14 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %8, %11, %6
%16 = phi i32 [ 1, %6 ], [ 1, %11 ], [ 0, %8 ], [ -1, %13 ]
ret i32 %16
}