#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_timing_adv(int fd) {
  long int *data;
  int timing_adv = 0;
  write(fd, "010E 1\r", 7);
  data = obd_get_bytes(fd, 1);
  if (data == NULL) {
    timing_adv = -1;
  } else {
    timing_adv = (int)data[2] / 2 - 64;
    free(data);
  }
  return timing_adv;
}


x86 assembly (clang, -O0):
<get_timing_adv>:
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_timing_adv+0x4e>
movl   $0xffffffff,-0x14(%rbp)
jmp    119d <get_timing_adv+0x6d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x40,%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_timing_adv>:
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     116e <get_timing_adv+0x3e>
mov    0x10(%rax),%ecx
mov    %ecx,%ebx
shr    $0x1f,%ebx
add    %ecx,%ebx
sar    %ebx
add    $0xffffffc0,%ebx
mov    %rax,%rdi
call   1030 <free@plt>
jmp    1173 <get_timing_adv+0x43>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"010E 1\0D\00"
define i32 @get_timing_adv(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 = sdiv i32 %16, 2
%18 = sub nsw i32 %17, 64
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"010E 1\0D\00"
define i32 @get_timing_adv(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 = sdiv i32 %8, 2
%10 = add nsw i32 %9, -64
%11 = tail call i32 @free(i64* %3)
br label %12
12: ; preds = %1, %5
%13 = phi i32 [ %10, %5 ], [ -1, %1 ]
ret i32 %13
}