#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 send_constant(char *);
int wait_for_main_prompt(int);
int wait_for_one_character();
int send_command(char *the_string, int add_cr, int expect_prompt) {
  int function_result;
  function_result = send_constant(the_string);
  if (function_result < 1) {
    return function_result;
  }
  if (add_cr) {
    function_result = send_constant("\r");
    if (function_result < 1) {
      return function_result;
    }
  }
  if (expect_prompt) {
    function_result = wait_for_one_character();
    if (function_result < 1) {
      return function_result;
    }
    function_result = wait_for_main_prompt(expect_prompt - 1);
    if (function_result < 1) {
      return function_result;
    }
  }
  return function_result;
}


x86 assembly (clang, -O0):
<send_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <send_constant@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1163 <send_command+0x33>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <send_command+0xbd>
cmpl   $0x0,-0x14(%rbp)
je     1196 <send_command+0x66>
lea    0xe8c(%rip),%rdi
call   1040 <send_constant@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1191 <send_command+0x61>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <send_command+0xbd>
jmp    1196 <send_command+0x66>
cmpl   $0x0,-0x18(%rbp)
je     11e7 <send_command+0xb7>
mov    $0x0,%al
call   1030 <wait_for_one_character@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    11bf <send_command+0x8f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <send_command+0xbd>
mov    -0x18(%rbp),%edi
sub    $0x1,%edi
call   1050 <wait_for_main_prompt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    11e2 <send_command+0xb2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <send_command+0xbd>
jmp    11e7 <send_command+0xb7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_command>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
call   1040 <send_constant@plt>
test   %eax,%eax
jle    1173 <send_command+0x43>
test   %ebp,%ebp
je     1154 <send_command+0x24>
lea    0xeb5(%rip),%rdi
call   1040 <send_constant@plt>
test   %eax,%eax
jle    1173 <send_command+0x43>
test   %ebx,%ebx
je     1173 <send_command+0x43>
xor    %eax,%eax
call   1030 <wait_for_one_character@plt>
test   %eax,%eax
jle    1173 <send_command+0x43>
add    $0xffffffff,%ebx
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <wait_for_main_prompt@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0D\00"
define i32 @send_command(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @send_constant(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* %8
store i32 %14, i32* %4
br label %45
15: ; preds = %3
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = call i32 @send_constant(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i32, i32* %8
store i32 %23, i32* %4
br label %45
24: ; preds = %18
br label %25
25: ; preds = %24, %15
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = call i32 (...) @wait_for_one_character()
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i32, i32* %8
store i32 %33, i32* %4
br label %45
34: ; preds = %28
%35 = load i32, i32* %7
%36 = sub nsw i32 %35, 1
%37 = call i32 @wait_for_main_prompt(i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = load i32, i32* %8
store i32 %41, i32* %4
br label %45
42: ; preds = %34
br label %43
43: ; preds = %42, %25
%44 = load i32, i32* %8
store i32 %44, i32* %4
br label %45
45: ; preds = %43, %40, %32, %22, %13
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0D\00"
define i32 @send_command(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @send_constant(i8* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = icmp eq i32 %1, 0
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i32 @send_constant(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp slt i32 %9, 1
br i1 %10, label %20, label %11
11: ; preds = %8, %6
%12 = phi i32 [ %9, %8 ], [ %4, %6 ]
%13 = icmp eq i32 %2, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = tail call i32 (...) @wait_for_one_character()
%16 = icmp slt i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = add nsw i32 %2, -1
%19 = tail call i32 @wait_for_main_prompt(i32 %18)
br label %20
20: ; preds = %17, %11, %14, %8, %3
%21 = phi i32 [ %4, %3 ], [ %9, %8 ], [ %15, %14 ], [ %19, %17 ], [ %12, %11 ]
ret i32 %21
}