#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 */
struct string {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ string_append_char(struct string *, char const);
int /*<<< orphan*/ string_clear(struct string *);
char *string_get_cstr(struct string const *);
size_t string_get_size(struct string const *);
void escape_command(const struct string *input, struct string *output) {
  const char *cstr = string_get_cstr(input);
  size_t len = string_get_size(input);
  size_t i;
  int new_line = 1;
  string_clear(output);
  for (i = 0; i < len; ++i) {
    if (!new_line || cstr[i] != '\t') {
      string_append_char(output, cstr[i]);
    }
    new_line = (cstr[i] == '\n');
  }
}


x86 assembly (clang, -O0):
<escape_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <string_get_cstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <string_get_size@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <string_clear@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11ef <escape_command+0xaf>
cmpl   $0x0,-0x2c(%rbp)
je     11af <escape_command+0x6f>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     11c4 <escape_command+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <string_append_char@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1182 <escape_command+0x42>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_command>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <string_get_cstr@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <string_get_size@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <string_clear@plt>
test   %r15,%r15
je     11b3 <escape_command+0x73>
mov    $0x1,%eax
xor    %ebx,%ebx
jmp    11a1 <escape_command+0x61>
nopw   0x0(%rax,%rax,1)
movsbl %cl,%esi
mov    %r14,%rdi
call   1030 <string_append_char@plt>
movzbl (%r12,%rbx,1),%edx
xor    %eax,%eax
cmp    $0xa,%dl
sete   %al
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b3 <escape_command+0x73>
movzbl (%r12,%rbx,1),%ecx
test   %eax,%eax
je     1180 <escape_command+0x40>
mov    $0x9,%dl
cmp    $0x9,%cl
je     1190 <escape_command+0x50>
jmp    1180 <escape_command+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.string = type { i32 }
define void @escape_command(%struct.string* %0, %struct.string* %1) {
%3 = alloca %struct.string*
%4 = alloca %struct.string*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store %struct.string* %0, %struct.string** %3
store %struct.string* %1, %struct.string** %4
%9 = load %struct.string*, %struct.string** %3
%10 = call i8* @string_get_cstr(%struct.string* %9)
store i8* %10, i8** %5
%11 = load %struct.string*, %struct.string** %3
%12 = call i64 @string_get_size(%struct.string* %11)
store i64 %12, i64* %6
store i32 1, i32* %8
%13 = load %struct.string*, %struct.string** %4
%14 = call i32 @string_clear(%struct.string* %13)
store i64 0, i64* %7
br label %15
15: ; preds = %44, %2
%16 = load i64, i64* %7
%17 = load i64, i64* %6
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %47
19: ; preds = %15
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i64, i64* %7
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 9
br i1 %28, label %29, label %36
29: ; preds = %22, %19
%30 = load %struct.string*, %struct.string** %4
%31 = load i8*, i8** %5
%32 = load i64, i64* %7
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @string_append_char(%struct.string* %30, i8 signext %34)
br label %36
36: ; preds = %29, %22
%37 = load i8*, i8** %5
%38 = load i64, i64* %7
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
%43 = zext i1 %42 to i32
store i32 %43, i32* %8
br label %44
44: ; preds = %36
%45 = load i64, i64* %7
%46 = add i64 %45, 1
store i64 %46, i64* %7
br label %15
47: ; preds = %15
ret void
}

LLVM IR (-O2):
%struct.string = type { i32 }
define void @escape_command(%struct.string* %0, %struct.string* %1) {
%3 = tail call i8* @string_get_cstr(%struct.string* %0)
%4 = tail call i64 @string_get_size(%struct.string* %0)
%5 = tail call i32 @string_clear(%struct.string* %1)
%6 = icmp eq i64 %4, 0
br i1 %6, label %25, label %7
7: ; preds = %2, %19
%8 = phi i32 [ %22, %19 ], [ 1, %2 ]
%9 = phi i64 [ %23, %19 ], [ 0, %2 ]
%10 = icmp ne i32 %8, 0
%11 = getelementptr inbounds i8, i8* %3, i64 %9
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 9
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %19, label %15
15: ; preds = %7
%16 = getelementptr inbounds i8, i8* %3, i64 %9
%17 = tail call i32 @string_append_char(%struct.string* %1, i8 signext %12)
%18 = load i8, i8* %16
br label %19
19: ; preds = %7, %15
%20 = phi i8 [ %18, %15 ], [ 9, %7 ]
%21 = icmp eq i8 %20, 10
%22 = zext i1 %21 to i32
%23 = add nuw i64 %9, 1
%24 = icmp eq i64 %23, %4
br i1 %24, label %25, label %7
25: ; preds = %19, %2
ret void
}