#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 obstack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ obstack_1grow(struct obstack *, char const);
int /*<<< orphan*/ obstack_grow(struct obstack *, char const *, int);
int /*<<< orphan*/ qu_append_c_name(struct obstack *, char const *);
int /*<<< orphan*/ qu_append_c_name_upper(struct obstack *, char const *);
int sprintf(char *, char *, ...);
int strlen(char const *);
void qu_code_growstr(const char *val, struct obstack *buf, const char *fmt) {
  const char *c;
  if (fmt == NULL) {
    obstack_grow(buf, val, strlen(val));
  } else {
    if (fmt[1] == 'q') {
      if (!val) {
        obstack_grow(buf, "NULL", 4);
        return;
      }
      obstack_1grow(buf, '"');
      for (c = val; *c; ++c) {
        if (*c < 32) {
          char tbuf[8];
          int tlen;
          switch (*c) {
          case '\r':
            tlen = sprintf(tbuf, "\\r");
            break;
          case '\n':
            tlen = sprintf(tbuf, "\\n");
            break;
          case '\t':
            tlen = sprintf(tbuf, "\\t");
            break;
          default:
            tlen = sprintf(tbuf, "\\x%02x", *c);
            break;
          }
          obstack_grow(buf, tbuf, tlen);
          continue;
        } else if (*c == '\\' || *c == '"') {
          obstack_1grow(buf, '\\');
          obstack_1grow(buf, *c);
        } else {
          obstack_1grow(buf, *c);
        }
      }
      obstack_1grow(buf, '"');
    } else if (fmt[1] == 'c') {
      qu_append_c_name(buf, val);
    } else if (fmt[1] == 'C') {
      qu_append_c_name_upper(buf, val);
    }
  }
}


x86 assembly (clang, -O0):
<qu_code_growstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ac <qu_code_growstr+0x4c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <obstack_grow@plt>
jmp    139f <qu_code_growstr+0x23f>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x71,%eax
jne    134f <qu_code_growstr+0x1ef>
cmpq   $0x0,-0x8(%rbp)
jne    11e2 <qu_code_growstr+0x82>
mov    -0x10(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x4,%edx
call   1040 <obstack_grow@plt>
jmp    139f <qu_code_growstr+0x23f>
mov    -0x10(%rbp),%rdi
mov    $0x22,%esi
call   1060 <obstack_1grow@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     133c <qu_code_growstr+0x1dc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    12ce <qu_code_growstr+0x16e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x9,%eax
je     1283 <qu_code_growstr+0x123>
jmp    122d <qu_code_growstr+0xcd>
mov    -0x44(%rbp),%eax
sub    $0xa,%eax
je     1269 <qu_code_growstr+0x109>
jmp    123e <qu_code_growstr+0xde>
mov    -0x44(%rbp),%eax
sub    $0xd,%eax
jne    129d <qu_code_growstr+0x13d>
jmp    124f <qu_code_growstr+0xef>
lea    -0x28(%rbp),%rdi
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
jmp    12b9 <qu_code_growstr+0x159>
lea    -0x28(%rbp),%rdi
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
jmp    12b9 <qu_code_growstr+0x159>
lea    -0x28(%rbp),%rdi
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
jmp    12b9 <qu_code_growstr+0x159>
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <obstack_grow@plt>
jmp    132b <qu_code_growstr+0x1cb>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     12ee <qu_code_growstr+0x18e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1311 <qu_code_growstr+0x1b1>
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1060 <obstack_1grow@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1060 <obstack_1grow@plt>
jmp    1321 <qu_code_growstr+0x1c1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1060 <obstack_1grow@plt>
jmp    1326 <qu_code_growstr+0x1c6>
jmp    132b <qu_code_growstr+0x1cb>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11f8 <qu_code_growstr+0x98>
mov    -0x10(%rbp),%rdi
mov    $0x22,%esi
call   1060 <obstack_1grow@plt>
jmp    139a <qu_code_growstr+0x23a>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x63,%eax
jne    1372 <qu_code_growstr+0x212>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <qu_append_c_name@plt>
jmp    1395 <qu_code_growstr+0x235>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x43,%eax
jne    1390 <qu_code_growstr+0x230>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <qu_append_c_name_upper@plt>
jmp    1395 <qu_code_growstr+0x235>
jmp    139a <qu_code_growstr+0x23a>
jmp    139f <qu_code_growstr+0x23f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qu_code_growstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdx,%rdx
je     11be <qu_code_growstr+0x5e>
mov    0x1(%rdx),%al
cmp    $0x43,%al
je     1282 <qu_code_growstr+0x122>
cmp    $0x63,%al
je     1298 <qu_code_growstr+0x138>
cmp    $0x71,%al
jne    12bb <qu_code_growstr+0x15b>
test   %rbx,%rbx
je     12c7 <qu_code_growstr+0x167>
mov    %r14,%rdi
mov    $0x22,%esi
call   1060 <obstack_1grow@plt>
mov    (%rbx),%al
test   %al,%al
je     12ae <qu_code_growstr+0x14e>
add    $0x1,%rbx
mov    %rsp,%r15
lea    0xe52(%rip),%r12
jmp    1207 <qu_code_growstr+0xa7>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <obstack_grow@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %eax,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <obstack_grow@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     12ae <qu_code_growstr+0x14e>
cmp    $0x1f,%al
jg     1230 <qu_code_growstr+0xd0>
movsbl %al,%edx
cmp    $0x9,%edx
je     1258 <qu_code_growstr+0xf8>
cmp    $0xa,%edx
je     126d <qu_code_growstr+0x10d>
cmp    $0xd,%edx
jne    11de <qu_code_growstr+0x7e>
movb   $0x0,0x2(%rsp)
movw   $0x725c,(%rsp)
mov    $0x2,%edx
jmp    11ed <qu_code_growstr+0x8d>
nop
cmp    $0x5c,%al
je     1238 <qu_code_growstr+0xd8>
cmp    $0x22,%al
jne    124b <qu_code_growstr+0xeb>
mov    %r14,%rdi
mov    $0x5c,%esi
call   1060 <obstack_1grow@plt>
movsbl -0x1(%rbx),%esi
jmp    124e <qu_code_growstr+0xee>
movsbl %al,%esi
mov    %r14,%rdi
call   1060 <obstack_1grow@plt>
jmp    11f8 <qu_code_growstr+0x98>
movb   $0x0,0x2(%rsp)
movw   $0x745c,(%rsp)
mov    $0x2,%edx
jmp    11ed <qu_code_growstr+0x8d>
movb   $0x0,0x2(%rsp)
movw   $0x6e5c,(%rsp)
mov    $0x2,%edx
jmp    11ed <qu_code_growstr+0x8d>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <qu_append_c_name_upper@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <qu_append_c_name@plt>
mov    %r14,%rdi
mov    $0x22,%esi
call   1060 <obstack_1grow@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd32(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
jmp    11ce <qu_code_growstr+0x6e>

LLVM IR (-O0):
%struct.obstack = type { i32 }
@.str = [5 x i8] c"NULL\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\t\00"
@.str.4 = [7 x i8] c"\\x%02x\00"
define void @qu_code_growstr(i8* %0, %struct.obstack* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca %struct.obstack*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [8 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store %struct.obstack* %1, %struct.obstack** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load %struct.obstack*, %struct.obstack** %5
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @obstack_grow(%struct.obstack* %13, i8* %14, i32 %16)
br label %120
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 113
br i1 %23, label %24, label %97
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load %struct.obstack*, %struct.obstack** %5
%29 = call i32 @obstack_grow(%struct.obstack* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
br label %120
30: ; preds = %24
%31 = load %struct.obstack*, %struct.obstack** %5
%32 = call i32 @obstack_1grow(%struct.obstack* %31, i8 signext 34)
%33 = load i8*, i8** %4
store i8* %33, i8** %7
br label %34
34: ; preds = %91, %30
%35 = load i8*, i8** %7
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %94
38: ; preds = %34
%39 = load i8*, i8** %7
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp slt i32 %41, 32
br i1 %42, label %43, label %67
43: ; preds = %38
%44 = load i8*, i8** %7
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
switch i32 %46, label %56 [
i32 13, label %47
i32 10, label %50
i32 9, label %53
]
47: ; preds = %43
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %49, i32* %9
br label %62
50: ; preds = %43
%51 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %52, i32* %9
br label %62
53: ; preds = %43
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 %55, i32* %9
br label %62
56: ; preds = %43
%57 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%58 = load i8*, i8** %7
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %60)
store i32 %61, i32* %9
br label %62
62: ; preds = %56, %53, %50, %47
%63 = load %struct.obstack*, %struct.obstack** %5
%64 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%65 = load i32, i32* %9
%66 = call i32 @obstack_grow(%struct.obstack* %63, i8* %64, i32 %65)
br label %91
67: ; preds = %38
%68 = load i8*, i8** %7
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 92
br i1 %71, label %77, label %72
72: ; preds = %67
%73 = load i8*, i8** %7
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 34
br i1 %76, label %77, label %84
77: ; preds = %72, %67
%78 = load %struct.obstack*, %struct.obstack** %5
%79 = call i32 @obstack_1grow(%struct.obstack* %78, i8 signext 92)
%80 = load %struct.obstack*, %struct.obstack** %5
%81 = load i8*, i8** %7
%82 = load i8, i8* %81
%83 = call i32 @obstack_1grow(%struct.obstack* %80, i8 signext %82)
br label %89
84: ; preds = %72
%85 = load %struct.obstack*, %struct.obstack** %5
%86 = load i8*, i8** %7
%87 = load i8, i8* %86
%88 = call i32 @obstack_1grow(%struct.obstack* %85, i8 signext %87)
br label %89
89: ; preds = %84, %77
br label %90
90: ; preds = %89
br label %91
91: ; preds = %90, %62
%92 = load i8*, i8** %7
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %7
br label %34
94: ; preds = %34
%95 = load %struct.obstack*, %struct.obstack** %5
%96 = call i32 @obstack_1grow(%struct.obstack* %95, i8 signext 34)
br label %119
97: ; preds = %18
%98 = load i8*, i8** %6
%99 = getelementptr inbounds i8, i8* %98, i64 1
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = icmp eq i32 %101, 99
br i1 %102, label %103, label %107
103: ; preds = %97
%104 = load %struct.obstack*, %struct.obstack** %5
%105 = load i8*, i8** %4
%106 = call i32 @qu_append_c_name(%struct.obstack* %104, i8* %105)
br label %118
107: ; preds = %97
%108 = load i8*, i8** %6
%109 = getelementptr inbounds i8, i8* %108, i64 1
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp eq i32 %111, 67
br i1 %112, label %113, label %117
113: ; preds = %107
%114 = load %struct.obstack*, %struct.obstack** %5
%115 = load i8*, i8** %4
%116 = call i32 @qu_append_c_name_upper(%struct.obstack* %114, i8* %115)
br label %117
117: ; preds = %113, %107
br label %118
118: ; preds = %117, %103
br label %119
119: ; preds = %118, %94
br label %120
120: ; preds = %27, %119, %12
ret void
}

LLVM IR (-O2):
%struct.obstack = type { i32 }
@.str = [5 x i8] c"NULL\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\t\00"
@.str.4 = [7 x i8] c"\\x%02x\00"
define void @qu_code_growstr(i8* %0, %struct.obstack* %1, i8* %2) {
%4 = alloca [8 x i8]
%5 = icmp eq i8* %2, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @obstack_grow(%struct.obstack* %1, i8* %0, i32 %7)
br label %53
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %2, i64 1
%11 = load i8, i8* %10
switch i8 %11, label %53 [
i8 113, label %12
i8 99, label %49
i8 67, label %51
]
12: ; preds = %9
%13 = icmp eq i8* %0, null
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @obstack_grow(%struct.obstack* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
br label %53
16: ; preds = %12
%17 = tail call i32 @obstack_1grow(%struct.obstack* %1, i8 signext 34)
%18 = load i8, i8* %0
%19 = icmp eq i8 %18, 0
br i1 %19, label %47, label %20
20: ; preds = %16
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
br label %22
22: ; preds = %20, %43
%23 = phi i8 [ %18, %20 ], [ %45, %43 ]
%24 = phi i8* [ %0, %20 ], [ %44, %43 ]
%25 = icmp slt i8 %23, 32
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = sext i8 %23 to i32
switch i32 %27, label %31 [
i32 13, label %28
i32 10, label %29
i32 9, label %30
]
28: ; preds = %26
br label %33
29: ; preds = %26
br label %33
30: ; preds = %26
br label %33
31: ; preds = %26
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %33
33: ; preds = %31, %30, %29, %28
%34 = phi i32 [ %32, %31 ], [ 2, %30 ], [ 2, %29 ], [ 2, %28 ]
%35 = call i32 @obstack_grow(%struct.obstack* %1, i8* %21, i32 %34)
br label %43
36: ; preds = %22
switch i8 %23, label %41 [
i8 92, label %37
i8 34, label %37
]
37: ; preds = %36, %36
%38 = call i32 @obstack_1grow(%struct.obstack* %1, i8 signext 92)
%39 = load i8, i8* %24
%40 = call i32 @obstack_1grow(%struct.obstack* %1, i8 signext %39)
br label %43
41: ; preds = %36
%42 = call i32 @obstack_1grow(%struct.obstack* %1, i8 signext %23)
br label %43
43: ; preds = %41, %37, %33
%44 = getelementptr inbounds i8, i8* %24, i64 1
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %22
47: ; preds = %43, %16
%48 = call i32 @obstack_1grow(%struct.obstack* %1, i8 signext 34)
br label %53
49: ; preds = %9
%50 = tail call i32 @qu_append_c_name(%struct.obstack* %1, i8* %0)
br label %53
51: ; preds = %9
%52 = tail call i32 @qu_append_c_name_upper(%struct.obstack* %1, i8* %0)
br label %53
53: ; preds = %6, %49, %51, %47, %9, %14
ret void
}