#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 */
typedef int /*<<< orphan*/ __u_char;

/* Variables and functions */
int atoi(char *);
int cbm_raw_read(int, char *, size_t);
scalar_t__ cbmarch_talk(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ cbmarch_untalk(int);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int cbm_device_status(int HandleDevice, __u_char DeviceAddress, void *Buffer,
                      size_t BufferLength) {
  int retValue;
  ;
  ;
  retValue = 99;
  if (Buffer && (BufferLength > 0)) {
    char *bufferToWrite = Buffer;
    bufferToWrite[--BufferLength] = '\0';
    strncpy(bufferToWrite, "99, DRIVER ERROR,00,00\r", BufferLength);
    if (cbmarch_talk(HandleDevice, DeviceAddress, 15) == 0) {
      int bytesRead = cbm_raw_read(HandleDevice, bufferToWrite, BufferLength);
      ;
      ;
      bufferToWrite[bytesRead] = '\0';
      cbmarch_untalk(HandleDevice);
    }
    retValue = atoi(bufferToWrite);
  }
  return retValue;
}


x86 assembly (clang, -O0):
<cbm_device_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x63,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1204 <cbm_device_status+0xb4>
cmpq   $0x0,-0x18(%rbp)
jbe    1204 <cbm_device_status+0xb4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xf,%edx
call   1050 <cbmarch_talk@plt>
cmp    $0x0,%rax
jne    11f8 <cbm_device_status+0xa8>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <cbm_raw_read@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
call   1060 <cbmarch_untalk@plt>
mov    -0x28(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbm_device_status>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     11cb <cbm_device_status+0x7b>
mov    %rcx,%rbp
test   %rcx,%rcx
je     11cb <cbm_device_status+0x7b>
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r14d
movb   $0x0,-0x1(%rdx,%rbp,1)
add    $0xffffffffffffffff,%rbp
lea    0xe83(%rip),%rsi
mov    %rdx,%rdi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    $0xf,%edx
call   1050 <cbmarch_talk@plt>
test   %rax,%rax
jne    11b9 <cbm_device_status+0x69>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <cbm_raw_read@plt>
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %r14d,%edi
call   1060 <cbmarch_untalk@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <atoi@plt>
mov    $0x63,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"99, DRIVER ERROR,00,00\0D\00"
define i32 @cbm_device_status(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 99, i32* %9
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %44
14: ; preds = %4
%15 = load i64, i64* %8
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %14
%18 = load i8*, i8** %7
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = load i64, i64* %8
%21 = add i64 %20, -1
store i64 %21, i64* %8
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %10
%24 = load i64, i64* %8
%25 = call i32 @strncpy(i8* %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i64 @cbmarch_talk(i32 %26, i32 %27, i32 15)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %17
%31 = load i32, i32* %5
%32 = load i8*, i8** %10
%33 = load i64, i64* %8
%34 = call i32 @cbm_raw_read(i32 %31, i8* %32, i64 %33)
store i32 %34, i32* %11
%35 = load i8*, i8** %10
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i32, i32* %5
%40 = call i32 @cbmarch_untalk(i32 %39)
br label %41
41: ; preds = %30, %17
%42 = load i8*, i8** %10
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %9
br label %44
44: ; preds = %41, %14, %4
%45 = load i32, i32* %9
ret i32 %45
}

LLVM IR (-O2):
@.str = [24 x i8] c"99, DRIVER ERROR,00,00\0D\00"
define i32 @cbm_device_status(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = icmp ne i8* %2, null
%6 = icmp ne i64 %3, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = add i64 %3, -1
%10 = getelementptr inbounds i8, i8* %2, i64 %9
store i8 0, i8* %10
%11 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %9)
%12 = tail call i64 @cbmarch_talk(i32 %0, i32 %1, i32 15)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = tail call i32 @cbm_raw_read(i32 %0, i8* %2, i64 %9)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @cbmarch_untalk(i32 %0)
br label %19
19: ; preds = %14, %8
%20 = tail call i32 @atoi(i8* %2)
br label %21
21: ; preds = %19, %4
%22 = phi i32 [ %20, %19 ], [ 99, %4 ]
ret i32 %22
}