#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 *);
int /*<<< orphan*/ printf(char *, char *);
char *strutil_insert(char *, char *, int);
int main(void) {
  char *str = "Hello, world!";
  char *extra = "beautiful ";
  char *expanded = strutil_insert(str, extra, 7);
  printf("Original: \"%s\"\n", str);
  printf("Expanded: \"%s\"\n", expanded);
  free(expanded);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x7,%edx
call   1040 <strutil_insert@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xea3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%r14
lea    0xecc(%rip),%rsi
mov    %r14,%rdi
mov    $0x7,%edx
call   1040 <strutil_insert@plt>
mov    %rax,%rbx
lea    0xec0(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
lea    0xec1(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [11 x i8] c"beautiful \00"
@.str.2 = [16 x i8] c"Original: \22%s\22\0A\00"
@.str.3 = [16 x i8] c"Expanded: \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %2
%6 = load i8*, i8** %3
%7 = call i8* @strutil_insert(i8* %5, i8* %6, i32 7)
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %4
%11 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %4
%13 = call i32 @free(i8* %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello, world!\00"
@.str.1 = [11 x i8] c"beautiful \00"
@.str.2 = [16 x i8] c"Original: \22%s\22\0A\00"
@.str.3 = [16 x i8] c"Expanded: \22%s\22\0A\00"
define i32 @main() {
%1 = tail call i8* @strutil_insert(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 7)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%4 = tail call i32 @free(i8* %1)
ret i32 0
}