#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*/ str;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
scalar_t__ isnumeric(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
int winusbtmc_find_devnum_by_string(char *);
int winusbtmc_recv_string(int, char *, int, int *);
int winusbtmc_send_string(int, char *);
void send_command(char *device, char *commandstr, bool getResponse) {
  int devnum;
  char str[8192];
  int ret;
  bool eom;
  if (isnumeric(device)) {
    devnum = atoi(device);
  } else {
    devnum = winusbtmc_find_devnum_by_string(device);
  }
  ret = winusbtmc_send_string(devnum, commandstr);
  if (ret < 0) {
    printf("ERROR: %d\n", ret);
    return;
  }
  if (getResponse) {
    do {
      ret = winusbtmc_recv_string(devnum, str, sizeof(str) - 1, &eom);
      if (ret < 0) {
        printf("ERROR: %d\n", ret);
        return;
      }
      fwrite(str, ret, 1, stdout);
    } while (!eom);
  }
}


x86 assembly (clang, -O0):
<send_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <isnumeric@plt>
cmp    $0x0,%rax
je     11aa <send_command+0x3a>
mov    -0x8(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11b6 <send_command+0x46>
mov    -0x8(%rbp),%rdi
call   1040 <winusbtmc_find_devnum_by_string@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <winusbtmc_send_string@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jge    11ec <send_command+0x7c>
mov    -0x2024(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
jmp    1279 <send_command+0x109>
cmpl   $0x0,-0x14(%rbp)
je     1279 <send_command+0x109>
jmp    11fb <send_command+0x8b>
mov    -0x18(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x1fff,%edx
lea    -0x2028(%rbp),%rcx
call   1030 <winusbtmc_recv_string@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jge    1240 <send_command+0xd0>
mov    -0x2024(%rbp),%esi
lea    0xdca(%rip),%rdi
call   1050 <printf@plt>
jmp    1279 <send_command+0x109>
lea    -0x2020(%rbp),%rdi
mov    -0x2024(%rbp),%esi
mov    0x2d8c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmpl   $0x0,-0x2028(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fb <send_command+0x8b>
jmp    1279 <send_command+0x109>
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_command>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2018,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1070 <isnumeric@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     119a <send_command+0x2a>
call   1080 <atoi@plt>
jmp    119f <send_command+0x2f>
call   1040 <winusbtmc_find_devnum_by_string@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
call   1060 <winusbtmc_send_string@plt>
test   %eax,%eax
js     1201 <send_command+0x91>
test   %r14d,%r14d
je     122a <send_command+0xba>
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r14
mov    0x2e1b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1fff,%edx
mov    %r14,%rcx
call   1030 <winusbtmc_recv_string@plt>
test   %eax,%eax
js     121c <send_command+0xac>
mov    (%r15),%ecx
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmpl   $0x0,0xc(%rsp)
je     11d0 <send_command+0x60>
jmp    122a <send_command+0xba>
lea    0xdf8(%rip),%rdi
mov    %eax,%esi
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
lea    0xddd(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"ERROR: %d\0A\00"
@stdout = global i32 0
define void @send_command(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8192 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i64 @isnumeric(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
br label %20
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @winusbtmc_find_devnum_by_string(i8* %18)
store i32 %19, i32* %7
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %7
%22 = load i8*, i8** %5
%23 = call i32 @winusbtmc_send_string(i32 %21, i8* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* %9
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %52
29: ; preds = %20
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %52
32: ; preds = %29
br label %33
33: ; preds = %47, %32
%34 = load i32, i32* %7
%35 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%36 = call i32 @winusbtmc_recv_string(i32 %34, i8* %35, i32 8191, i32* %10)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i32, i32* %9
%41 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %52
42: ; preds = %33
%43 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%44 = load i32, i32* %9
%45 = load i32, i32* @stdout
%46 = call i32 @fwrite(i8* %43, i32 %44, i32 1, i32 %45)
br label %47
47: ; preds = %42
%48 = load i32, i32* %10
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
br i1 %50, label %33, label %51
51: ; preds = %47
br label %52
52: ; preds = %26, %39, %51, %29
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"ERROR: %d\0A\00"
@stdout = global i32 0
define void @send_command(i8* %0, i8* %1, i32 %2) {
%4 = alloca [8192 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = tail call i64 @isnumeric(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i32 @atoi(i8* %0)
br label %14
12: ; preds = %3
%13 = tail call i32 @winusbtmc_find_devnum_by_string(i8* %0)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %11, %10 ], [ %13, %12 ]
%16 = tail call i32 @winusbtmc_send_string(i32 %15, i8* %1)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %32
20: ; preds = %14
%21 = icmp eq i32 %2, 0
br i1 %21, label %32, label %22
22: ; preds = %20, %27
%23 = call i32 @winusbtmc_recv_string(i32 %15, i8* %6, i32 8191, i32* %5)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %32
27: ; preds = %22
%28 = load i32, i32* @stdout
%29 = call i32 @fwrite(i8* %6, i32 %23, i32 1, i32 %28)
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 0
br i1 %31, label %22, label %32
32: ; preds = %27, %20, %25, %18
ret void
}