#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*/ free(long *);
long *obd_get_bytes(int, int);
int /*<<< orphan*/ write(int, char *, int);
int get_rpm(int fd) {
  long int *data;
  int rpm;
  write(fd, "010C 1\r", 7);
  data = obd_get_bytes(fd, 2);
  if (data == NULL) {
    rpm = -1;
  } else {
    rpm = ((data[2] * 256) + data[3]) / 4;
    free(data);
  }
  return rpm;
}


x86 assembly (clang, -O0):
<get_rpm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xebb(%rip),%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1050 <obd_get_bytes@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <get_rpm+0x47>
movl   $0xffffffff,-0x14(%rbp)
jmp    11a1 <get_rpm+0x71>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
shl    $0x8,%rax
mov    -0x10(%rbp),%rcx
add    0x18(%rcx),%rax
mov    $0x4,%ecx
cqto
idiv   %rcx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rpm>:
push   %rbx
mov    %edi,%ebx
lea    0xec6(%rip),%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1050 <obd_get_bytes@plt>
test   %rax,%rax
je     117e <get_rpm+0x4e>
mov    0x10(%rax),%rcx
mov    0x18(%rax),%rdx
shl    $0x8,%rcx
lea    (%rcx,%rdx,1),%rbx
add    $0x3,%rbx
add    %rdx,%rcx
cmovns %rcx,%rbx
shr    $0x2,%rbx
mov    %rax,%rdi
call   1030 <free@plt>
jmp    1183 <get_rpm+0x53>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"010C 1\0D\00"
define i32 @get_rpm(i32 %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%7 = load i32, i32* %2
%8 = call i64* @obd_get_bytes(i32 %7, i32 2)
store i64* %8, i64** %3
%9 = load i64*, i64** %3
%10 = icmp eq i64* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %4
br label %25
12: ; preds = %1
%13 = load i64*, i64** %3
%14 = getelementptr inbounds i64, i64* %13, i64 2
%15 = load i64, i64* %14
%16 = mul nsw i64 %15, 256
%17 = load i64*, i64** %3
%18 = getelementptr inbounds i64, i64* %17, i64 3
%19 = load i64, i64* %18
%20 = add nsw i64 %16, %19
%21 = sdiv i64 %20, 4
%22 = trunc i64 %21 to i32
store i32 %22, i32* %4
%23 = load i64*, i64** %3
%24 = call i32 @free(i64* %23)
br label %25
25: ; preds = %12, %11
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [8 x i8] c"010C 1\0D\00"
define i32 @get_rpm(i32 %0) {
%2 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%3 = tail call i64* @obd_get_bytes(i32 %0, i32 2)
%4 = icmp eq i64* %3, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = getelementptr inbounds i64, i64* %3, i64 2
%7 = load i64, i64* %6
%8 = shl nsw i64 %7, 8
%9 = getelementptr inbounds i64, i64* %3, i64 3
%10 = load i64, i64* %9
%11 = add nsw i64 %8, %10
%12 = sdiv i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = tail call i32 @free(i64* %3)
br label %15
15: ; preds = %1, %5
%16 = phi i32 [ %13, %5 ], [ -1, %1 ]
ret i32 %16
}