#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 *calloc(int, int);
char *prependString(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *insert_after_struct(char *dst, char *toInsert) {
  char *structPosition = strstr(dst, "struct");
  int length = strlen(dst) + strlen(toInsert) + 2;
  char *res = calloc(length, sizeof(char));
  strcpy(res, "typedef struct ");
  res = prependString(res, toInsert);
  res = prependString(res, structPosition + 6);
  return res;
}


x86 assembly (clang, -O0):
<insert_after_struct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <prependString@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x6,%rsi
call   1060 <prependString@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_after_struct>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9e(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe71(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <prependString@plt>
add    $0x6,%r15
mov    %rax,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <prependString@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"struct\00"
@.str.1 = [16 x i8] c"typedef struct \00"
define i8* @insert_after_struct(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = add nsw i32 %14, 2
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i8* @calloc(i32 %16, i32 1)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** %7
%21 = load i8*, i8** %4
%22 = call i8* @prependString(i8* %20, i8* %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 6
%26 = call i8* @prependString(i8* %23, i8* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
ret i8* %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"struct\00"
@.str.1 = [16 x i8] c"typedef struct \00"
define i8* @insert_after_struct(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 2
%7 = add i32 %6, %5
%8 = tail call i8* @calloc(i32 %7, i32 1)
%9 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i8* @prependString(i8* %8, i8* %1)
%11 = getelementptr inbounds i8, i8* %3, i64 6
%12 = tail call i8* @prependString(i8* %10, i8* %11)
ret i8* %12
}