#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 */
char *emalloc(int);
int strlen(char const *);
char *MAKEFLAGS_quote(const char *str) {
  char *ret, *q;
  const char *p;
  ret = emalloc(strlen(str) * 2 + 1);
  p = str;
  q = ret;
  while (*p != '\0') {
    switch (*p) {
    case ' ':
    case '\t':
      *q++ = '\\';
      break;
    default:
      break;
    }
    *q++ = *p++;
  }
  *q++ = '\0';
  return (ret);
}


x86 assembly (clang, -O0):
<MAKEFLAGS_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1040 <emalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d2 <MAKEFLAGS_quote+0xb2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x9,%eax
je     118f <MAKEFLAGS_quote+0x6f>
jmp    117e <MAKEFLAGS_quote+0x5e>
mov    -0x24(%rbp),%eax
sub    $0x20,%eax
jne    11a6 <MAKEFLAGS_quote+0x86>
jmp    118f <MAKEFLAGS_quote+0x6f>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
jmp    11ab <MAKEFLAGS_quote+0x8b>
jmp    11ab <MAKEFLAGS_quote+0x8b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1156 <MAKEFLAGS_quote+0x36>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MAKEFLAGS_quote>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1040 <emalloc@plt>
mov    (%rbx),%dl
mov    %rax,%rcx
test   %dl,%dl
je     117b <MAKEFLAGS_quote+0x5b>
add    $0x1,%rbx
mov    %rax,%rcx
jmp    116c <MAKEFLAGS_quote+0x4c>
cs nopw 0x0(%rax,%rax,1)
movb   $0x5c,(%rcx)
add    $0x1,%rcx
movzbl -0x1(%rbx),%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
movzbl (%rbx),%edx
add    $0x1,%rbx
test   %dl,%dl
je     117b <MAKEFLAGS_quote+0x5b>
movsbl %dl,%esi
cmp    $0x20,%esi
je     1150 <MAKEFLAGS_quote+0x30>
cmp    $0x9,%esi
je     1150 <MAKEFLAGS_quote+0x30>
jmp    115b <MAKEFLAGS_quote+0x3b>
movb   $0x0,(%rcx)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @MAKEFLAGS_quote(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = mul nsw i32 %7, 2
%9 = add nsw i32 %8, 1
%10 = call i8* @emalloc(i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %2
store i8* %11, i8** %5
%12 = load i8*, i8** %3
store i8* %12, i8** %4
br label %13
13: ; preds = %26, %1
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %25 [
i32 32, label %22
i32 9, label %22
]
22: ; preds = %18, %18
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 92, i8* %23
br label %26
25: ; preds = %18
br label %26
26: ; preds = %25, %22
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
%29 = load i8, i8* %27
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 %29, i8* %30
br label %13
32: ; preds = %13
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
store i8 0, i8* %33
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @MAKEFLAGS_quote(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i8* @emalloc(i32 %4)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %1, %16
%9 = phi i8 [ %21, %16 ], [ %6, %1 ]
%10 = phi i8* [ %19, %16 ], [ %0, %1 ]
%11 = phi i8* [ %20, %16 ], [ %5, %1 ]
%12 = sext i8 %9 to i32
switch i32 %12, label %16 [
i32 32, label %13
i32 9, label %13
]
13: ; preds = %8, %8
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 92, i8* %11
%15 = load i8, i8* %10
br label %16
16: ; preds = %8, %13
%17 = phi i8 [ %9, %8 ], [ %15, %13 ]
%18 = phi i8* [ %11, %8 ], [ %14, %13 ]
%19 = getelementptr inbounds i8, i8* %10, i64 1
%20 = getelementptr inbounds i8, i8* %18, i64 1
store i8 %17, i8* %18
%21 = load i8, i8* %19
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %8
23: ; preds = %16, %1
%24 = phi i8* [ %5, %1 ], [ %20, %16 ]
store i8 0, i8* %24
ret i8* %5
}