#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*/ obd_read(int, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
bool obd_reset(int fd) {
  char buf[50];
  write(fd, "ATZ\r", 4);
  usleep(1000000);
  obd_read(fd, buf);
  if (strcmp(buf, "ELM327 v1.5") == 0)
    return true;
  else {
    return false;
  }
}


x86 assembly (clang, -O0):
<obd_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xeab(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    $0xf4240,%edi
call   1060 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1050 <obd_read@plt>
lea    -0x40(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    119b <obd_reset+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <obd_reset+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obd_reset>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
lea    0xeb0(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    $0xf4240,%edi
call   1060 <usleep@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <obd_read@plt>
lea    0xe8d(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"ATZ\0D\00"
@.str.1 = [12 x i8] c"ELM327 v1.5\00"
define i32 @obd_reset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @write(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = call i32 @usleep(i32 1000000)
%8 = load i32, i32* %3
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = call i32 @obd_read(i32 %8, i8* %9)
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %16
15: ; preds = %1
store i32 0, i32* %2
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"ATZ\0D\00"
@.str.1 = [12 x i8] c"ELM327 v1.5\00"
define i32 @obd_reset(i32 %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%5 = tail call i32 @usleep(i32 1000000)
%6 = call i32 @obd_read(i32 %0, i8* %3)
%7 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
ret i32 %9
}