#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*/ calc_strip_offsets(char *, char *, size_t *, size_t *,
                                      size_t *);
char *malloc(size_t);
char *strstrip_dup(char *str, char *chars) {
  size_t len, l, r, new_len;
  char *new, *head;
  size_t i;
  if (chars == NULL)
    chars = " \t\n\v\f\r";
  calc_strip_offsets(str, chars, &len, &l, &r);
  new_len = len - (l + r);
  new = malloc(new_len + 1);
  if (new == NULL)
    return NULL;
  head = str + l;
  for (i = 0; i < new_len; ++i)
    new[i] = head[i];
  new[new_len] = '\0';
  return new;
}


x86 assembly (clang, -O0):
<strstrip_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1146 <strstrip_dup+0x26>
lea    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1040 <calc_strip_offsets@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    119b <strstrip_dup+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <strstrip_dup+0xd8>
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11e4 <strstrip_dup+0xc4>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11af <strstrip_dup+0x8f>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrip_dup>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
test   %rsi,%rsi
lea    0xeb6(%rip),%rax
cmove  %rax,%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1050 <calc_strip_offsets@plt>
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%r12
mov    0x8(%rsp),%rbx
add    %r12,%rbx
mov    %rbx,%rax
neg    %rax
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     11ab <strstrip_dup+0x7b>
sub    %rbx,%r15
je     11a5 <strstrip_dup+0x75>
add    %r12,%r14
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <memcpy@plt>
movb   $0x0,0x0(%r13,%r15,1)
mov    %r13,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c" \09\0A\0B\0C\0D\00"
define i8* @strstrip_dup(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %5
br label %16
16: ; preds = %15, %2
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @calc_strip_offsets(i8* %17, i8* %18, i64* %6, i64* %7, i64* %8)
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = load i64, i64* %8
%23 = add i64 %21, %22
%24 = sub i64 %20, %23
store i64 %24, i64* %9
%25 = load i64, i64* %9
%26 = add i64 %25, 1
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %16
store i8* null, i8** %3
br label %55
31: ; preds = %16
%32 = load i8*, i8** %4
%33 = load i64, i64* %7
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %11
store i64 0, i64* %12
br label %35
35: ; preds = %47, %31
%36 = load i64, i64* %12
%37 = load i64, i64* %9
%38 = icmp ult i64 %36, %37
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = load i8*, i8** %11
%41 = load i64, i64* %12
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i8, i8* %42
%44 = load i8*, i8** %10
%45 = load i64, i64* %12
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8 %43, i8* %46
br label %47
47: ; preds = %39
%48 = load i64, i64* %12
%49 = add i64 %48, 1
store i64 %49, i64* %12
br label %35
50: ; preds = %35
%51 = load i8*, i8** %10
%52 = load i64, i64* %9
%53 = getelementptr inbounds i8, i8* %51, i64 %52
store i8 0, i8* %53
%54 = load i8*, i8** %10
store i8* %54, i8** %3
br label %55
55: ; preds = %50, %30
%56 = load i8*, i8** %3
ret i8* %56
}

LLVM IR (-O2):
@.str = [7 x i8] c" \09\0A\0B\0C\0D\00"
define noalias i8* @strstrip_dup(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = icmp eq i8* %1, null
%10 = select i1 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1
%11 = call i32 @calc_strip_offsets(i8* %0, i8* %10, i64* %3, i64* %4, i64* %5)
%12 = load i64, i64* %3
%13 = load i64, i64* %4
%14 = load i64, i64* %5
%15 = add i64 %13, %14
%16 = sub i64 %12, %15
%17 = add i64 %16, 1
%18 = call i8* @malloc(i64 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %26, label %20
20: ; preds = %2
%21 = icmp eq i64 %16, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = getelementptr i8, i8* %0, i64 %13
br label %24
24: ; preds = %22, %20
%25 = getelementptr inbounds i8, i8* %18, i64 %16
store i8 0, i8* %25
br label %26
26: ; preds = %2, %24
ret i8* %18
}