#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*/ enough_mem(char *);
scalar_t__ malloc(int);
char *quotstrtok(char const *, char const *, int *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
int strlen(char const *);
char *quotstrtok_prepend(const char *prefix, const char *s, const char *delim,
                         int *past_offset) {
  char *qstr = quotstrtok(s, delim, past_offset);
  char *nstr;
  int newsize;
  if (!qstr) {
    return qstr;
  }
  newsize = strlen(qstr) + strlen(prefix) + 1;
  nstr = (char *)malloc(newsize);
  enough_mem(nstr);
  snprintf(nstr, newsize, "%s%s", prefix, qstr);
  return nstr;
}


x86 assembly (clang, -O0):
<quotstrtok_prepend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <quotstrtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1195 <quotstrtok_prepend+0x45>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <quotstrtok_prepend+0x9f>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <enough_mem@plt>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe1e(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quotstrtok_prepend>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1030 <quotstrtok@plt>
test   %rax,%rax
je     11b3 <quotstrtok_prepend+0x63>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <enough_mem@plt>
lea    0xe5f(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <snprintf@plt>
jmp    11b5 <quotstrtok_prepend+0x65>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define i8* @quotstrtok_prepend(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%13 = load i8*, i8** %7
%14 = load i8*, i8** %8
%15 = load i32*, i32** %9
%16 = call i8* @quotstrtok(i8* %13, i8* %14, i32* %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %4
%20 = load i8*, i8** %10
store i8* %20, i8** %5
br label %39
21: ; preds = %4
%22 = load i8*, i8** %10
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %23, %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %12
%28 = load i32, i32* %12
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %11
%31 = load i8*, i8** %11
%32 = call i32 @enough_mem(i8* %31)
%33 = load i8*, i8** %11
%34 = load i32, i32* %12
%35 = load i8*, i8** %6
%36 = load i8*, i8** %10
%37 = call i32 @snprintf(i8* %33, i32 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i8*, i8** %11
store i8* %38, i8** %5
br label %39
39: ; preds = %21, %19
%40 = load i8*, i8** %5
ret i8* %40
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define i8* @quotstrtok_prepend(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = tail call i8* @quotstrtok(i8* %1, i8* %2, i32* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %5)
%9 = tail call i32 @strlen(i8* %0)
%10 = add i32 %8, 1
%11 = add i32 %10, %9
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @enough_mem(i8* %13)
%15 = tail call i32 @snprintf(i8* %13, i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %5)
br label %16
16: ; preds = %4, %7
%17 = phi i8* [ %13, %7 ], [ null, %4 ]
ret i8* %17
}