#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_throttle(int fd) {
  long int *data;
  int throttle = 0;
  write(fd, "0111 1\r", 7);
  data = obd_get_bytes(fd, 1);
  if (data == NULL) {
    throttle = -1;
  } else {
    throttle = (int)data[2] * 100 / 255;
    free(data);
  }
  return throttle;
}


x86 assembly (clang, -O0):
<get_throttle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    0xeb4(%rip),%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <obd_get_bytes@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117e <get_throttle+0x4e>
movl   $0xffffffff,-0x14(%rbp)
jmp    119d <get_throttle+0x6d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
imul   $0x64,%eax,%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
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_throttle>:
push   %rbx
mov    %edi,%ebx
lea    0xec6(%rip),%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <obd_get_bytes@plt>
test   %rax,%rax
je     117d <get_throttle+0x4d>
imul   $0x64,0x10(%rax),%ecx
movslq %ecx,%rbx
imul   $0xffffffff80808081,%rbx,%rcx
shr    $0x20,%rcx
add    %ecx,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x7,%ebx
add    %ecx,%ebx
mov    %rax,%rdi
call   1030 <free@plt>
jmp    1182 <get_throttle+0x52>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"0111 1\0D\00"
define i32 @get_throttle(i32 %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
%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 1)
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 %21
12: ; preds = %1
%13 = load i64*, i64** %3
%14 = getelementptr inbounds i64, i64* %13, i64 2
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = mul nsw i32 %16, 100
%18 = sdiv i32 %17, 255
store i32 %18, i32* %4
%19 = load i64*, i64** %3
%20 = call i32 @free(i64* %19)
br label %21
21: ; preds = %12, %11
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@.str = [8 x i8] c"0111 1\0D\00"
define i32 @get_throttle(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 1)
%4 = icmp eq i64* %3, null
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = getelementptr inbounds i64, i64* %3, i64 2
%7 = load i64, i64* %6
%8 = trunc i64 %7 to i32
%9 = mul nsw i32 %8, 100
%10 = sdiv i32 %9, 255
%11 = tail call i32 @free(i64* %3)
br label %12
12: ; preds = %1, %5
%13 = phi i32 [ %10, %5 ], [ -1, %1 ]
ret i32 %13
}