#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 *strdup(char *);
int strlen(char *);
char *stripCharsFromStringForwards(int count, char *initialString,
                                   char **theRest) {
  int stripPosition;
  char *strippedString;
  char *rest;
  if (count > strlen(initialString))
    stripPosition = strlen(initialString);
  else
    stripPosition = count;
  rest = strdup(&initialString[stripPosition]);
  strippedString = strdup(initialString);
  strippedString[stripPosition] = '\0';
  *theRest = rest;
  return strippedString;
}


x86 assembly (clang, -O0):
<stripCharsFromStringForwards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jle    1160 <stripCharsFromStringForwards+0x40>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
jmp    1166 <stripCharsFromStringForwards+0x46>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1040 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripCharsFromStringForwards>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    %ebp,%eax
jge    1145 <stripCharsFromStringForwards+0x25>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rdi
call   1040 <strdup@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strdup@plt>
movb   $0x0,(%rax,%rbp,1)
mov    %r15,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @stripCharsFromStringForwards(i32 %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %10, %12
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %7
br label %19
17: ; preds = %3
%18 = load i32, i32* %4
store i32 %18, i32* %7
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %5
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %9
%32 = load i8**, i8*** %6
store i8* %31, i8** %32
%33 = load i8*, i8** %8
ret i8* %33
}

LLVM IR (-O2):
define noalias i8* @stripCharsFromStringForwards(i32 %0, i8* %1, i8** nocapture writeonly %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp slt i32 %4, %0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ %7, %6 ], [ %0, %3 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = tail call i8* @strdup(i8* %11)
%13 = tail call i8* @strdup(i8* %1)
%14 = getelementptr inbounds i8, i8* %13, i64 %10
store i8 0, i8* %14
store i8* %12, i8** %2
ret i8* %13
}