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


x86 assembly (clang, -O0):
<get_maf>:
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_maf+0x4e>
movl   $0xffffffff,-0x14(%rbp)
jmp    119a <get_maf+0x6a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    $0x64,%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_maf>:
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     1177 <get_maf+0x47>
movslq 0x10(%rax),%rcx
imul   $0x51eb851f,%rcx,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rbx
add    %ecx,%ebx
mov    %rax,%rdi
call   1030 <free@plt>
jmp    117c <get_maf+0x4c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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