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

/* Variables and functions */
int /*<<< orphan*/ mgostring_add(struct MgoString *, char *);
char *mgostring_c_str(struct MgoString *);
struct MgoString *mgostring_construct(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mgostring_destruct(struct MgoString *);
int /*<<< orphan*/ mgostring_replace(struct MgoString *, char *, char *);
int /*<<< orphan*/ mgostring_trim(struct MgoString *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  struct MgoString *s;
  s = mgostring_construct("    Hello", 0);
  mgostring_add(s, " test");
  mgostring_add(s, ", ");
  mgostring_add(
      s, "the cat sat on the mat. All your base are belong to us.         ");
  mgostring_trim(s);
  printf("\"%s\"\n", mgostring_c_str(s));
  mgostring_replace(s, "e", "(THE LETTER \"E\" WAS HERE)");
  printf("\"%s\"\n", mgostring_c_str(s));
  mgostring_destruct(s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe7a(%rip),%rdi
xor    %esi,%esi
call   1080 <mgostring_construct@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1060 <mgostring_add@plt>
mov    -0x18(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1060 <mgostring_add@plt>
mov    -0x18(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1060 <mgostring_add@plt>
mov    -0x18(%rbp),%rdi
call   1030 <mgostring_trim@plt>
mov    -0x18(%rbp),%rdi
call   1040 <mgostring_c_str@plt>
mov    %rax,%rsi
lea    0xe77(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
lea    0xe68(%rip),%rdx
call   1090 <mgostring_replace@plt>
mov    -0x18(%rbp),%rdi
call   1040 <mgostring_c_str@plt>
mov    %rax,%rsi
lea    0xe48(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <mgostring_destruct@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
xor    %esi,%esi
call   1080 <mgostring_construct@plt>
mov    %rax,%rbx
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
call   1060 <mgostring_add@plt>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1060 <mgostring_add@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1060 <mgostring_add@plt>
mov    %rbx,%rdi
call   1030 <mgostring_trim@plt>
mov    %rbx,%rdi
call   1040 <mgostring_c_str@plt>
lea    0xe8b(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
lea    0xe7f(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    %rbx,%rdi
call   1090 <mgostring_replace@plt>
mov    %rbx,%rdi
call   1040 <mgostring_c_str@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <mgostring_destruct@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.MgoString = type { i32 }
@.str = [10 x i8] c" Hello\00"
@.str.1 = [6 x i8] c" test\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [65 x i8] c"the cat sat on the mat. All your base are belong to us. \00"
@.str.4 = [6 x i8] c"\22%s\22\0A\00"
@.str.5 = [2 x i8] c"e\00"
@.str.6 = [26 x i8] c"(THE LETTER \22E\22 WAS HERE)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.MgoString*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call %struct.MgoString* @mgostring_construct(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
store %struct.MgoString* %6, %struct.MgoString** %5
%7 = load %struct.MgoString*, %struct.MgoString** %5
%8 = call i32 @mgostring_add(%struct.MgoString* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = load %struct.MgoString*, %struct.MgoString** %5
%10 = call i32 @mgostring_add(%struct.MgoString* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = load %struct.MgoString*, %struct.MgoString** %5
%12 = call i32 @mgostring_add(%struct.MgoString* %11, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%13 = load %struct.MgoString*, %struct.MgoString** %5
%14 = call i32 @mgostring_trim(%struct.MgoString* %13)
%15 = load %struct.MgoString*, %struct.MgoString** %5
%16 = call i8* @mgostring_c_str(%struct.MgoString* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load %struct.MgoString*, %struct.MgoString** %5
%19 = call i32 @mgostring_replace(%struct.MgoString* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%20 = load %struct.MgoString*, %struct.MgoString** %5
%21 = call i8* @mgostring_c_str(%struct.MgoString* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = load %struct.MgoString*, %struct.MgoString** %5
%24 = call i32 @mgostring_destruct(%struct.MgoString* %23)
ret i32 0
}

LLVM IR (-O2):
%struct.MgoString = type { i32 }
@.str = [10 x i8] c" Hello\00"
@.str.1 = [6 x i8] c" test\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [65 x i8] c"the cat sat on the mat. All your base are belong to us. \00"
@.str.4 = [6 x i8] c"\22%s\22\0A\00"
@.str.5 = [2 x i8] c"e\00"
@.str.6 = [26 x i8] c"(THE LETTER \22E\22 WAS HERE)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.MgoString* @mgostring_construct(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = tail call i32 @mgostring_add(%struct.MgoString* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @mgostring_add(%struct.MgoString* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @mgostring_add(%struct.MgoString* %3, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @mgostring_trim(%struct.MgoString* %3)
%8 = tail call i8* @mgostring_c_str(%struct.MgoString* %3)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%10 = tail call i32 @mgostring_replace(%struct.MgoString* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%11 = tail call i8* @mgostring_c_str(%struct.MgoString* %3)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = tail call i32 @mgostring_destruct(%struct.MgoString* %3)
ret i32 0
}