#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(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ print_error(char *);
int /*<<< orphan*/ removeCommand(char const *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
void removeMonitor(const char *command) {
  char *buf;
  removeCommand(command);
  buf = (char *)malloc(strlen(command) + 2);
  if (!buf) {
    print_error("Out of memory");
    return;
  }
  strcpy(buf, command);
  strcat(buf, "?");
  removeCommand(buf);
  free(buf);
}


x86 assembly (clang, -O0):
<removeMonitor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <removeCommand@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ba <removeMonitor+0x4a>
lea    0xe50(%rip),%rdi
call   1050 <print_error@plt>
jmp    11e9 <removeMonitor+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1090 <removeCommand@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeMonitor>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1090 <removeCommand@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x2(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11c6 <removeMonitor+0x56>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1090 <removeCommand@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
lea    0xe33(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <print_error@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Out of memory\00"
@.str.1 = [2 x i8] c"?\00"
define void @removeMonitor(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @removeCommand(i8* %4)
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 2
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @print_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %25
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %3
%22 = call i32 @removeCommand(i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %15, %13
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Out of memory\00"
@.str.1 = [2 x i8] c"?\00"
define void @removeMonitor(i8* %0) {
%2 = tail call i32 @removeCommand(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 2
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @print_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %1
%11 = tail call i32 @strcpy(i8* %6, i8* %0)
%12 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @removeCommand(i8* %6)
%14 = tail call i32 @free(i8* %6)
br label %15
15: ; preds = %10, %8
ret void
}