#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_engine_temp(int fd) {
  long int *data;
  int engine_temp = 0;
  write(fd, "0105 1\r", 7);
  data = obd_get_bytes(fd, 1);
  if (data == NULL) {
    engine_temp = -1;
  } else {
    engine_temp = (int)data[2] - 40;
    free(data);
  }
  return engine_temp;
}


x86 assembly (clang, -O0):
<get_engine_temp>:
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_engine_temp+0x4e>
movl   $0xffffffff,-0x14(%rbp)
jmp    1195 <get_engine_temp+0x65>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
sub    $0x28,%eax
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_engine_temp>:
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     1165 <get_engine_temp+0x35>
mov    0x10(%rax),%ebx
add    $0xffffffd8,%ebx
mov    %rax,%rdi
call   1030 <free@plt>
jmp    116a <get_engine_temp+0x3a>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"0105 1\0D\00"
define i32 @get_engine_temp(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 %20
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 = sub nsw i32 %16, 40
store i32 %17, i32* %4
%18 = load i64*, i64** %3
%19 = call i32 @free(i64* %18)
br label %20
20: ; preds = %12, %11
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@.str = [8 x i8] c"0105 1\0D\00"
define i32 @get_engine_temp(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 %11, 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 = add nsw i32 %8, -40
%10 = tail call i32 @free(i64* %3)
br label %11
11: ; preds = %1, %5
%12 = phi i32 [ %9, %5 ], [ -1, %1 ]
ret i32 %12
}