#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
void strpack(char *buf, int from, int to) {
  int i = 0, j = 0, k = 0;
  int numchars = (to - from) + 1;
  char *tmpbuf = malloc(numchars * sizeof(char));
  if (tmpbuf == 0) {
    fprintf(stderr, "malloc failed\n");
    return;
  }
  strncpy(tmpbuf, buf + from, numchars);
  memset(buf + from, 0, numchars);
  i = 0;
  while (tmpbuf[i] == ' ')
    i++;
  j = 0;
  k = 0;
  for (j = i; j < numchars; j++) {
    buf[from + k] = tmpbuf[j];
    k++;
  }
  free(tmpbuf);
}


x86 assembly (clang, -O0):
<strpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bb <strpack+0x6b>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
jmp    126c <strpack+0x11c>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1211 <strpack+0xc1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <strpack+0x9e>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1263 <strpack+0x113>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1225 <strpack+0xd5>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strpack>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
sub    %esi,%r15d
lea    0x1(%r15),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11ea <strpack+0x8a>
mov    %rax,%rbx
movslq %r12d,%rax
add    %rax,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
mov    $0xffffffffffffffff,%rax
nopl   (%rax)
cmpb   $0x20,0x1(%rbx,%rax,1)
lea    0x1(%rax),%rax
je     11b0 <strpack+0x50>
cmp    %eax,%r15d
jl     11da <strpack+0x7a>
mov    %eax,%ecx
mov    %rbx,%rsi
add    %rcx,%rsi
sub    %eax,%r15d
add    $0x1,%r15
mov    %r14,%rdi
mov    %r15,%rdx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
define void @strpack(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = sub nsw i32 %12, %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %77
26: ; preds = %3
%27 = load i8*, i8** %11
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i32, i32* %10
%33 = call i32 @strncpy(i8* %27, i8* %31, i32 %32)
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i32, i32* %10
%39 = call i32 @memset(i8* %37, i32 0, i32 %38)
store i32 0, i32* %7
br label %40
40: ; preds = %48, %26
%41 = load i8*, i8** %11
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 32
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %40
51: ; preds = %40
store i32 0, i32* %8
store i32 0, i32* %9
%52 = load i32, i32* %7
store i32 %52, i32* %8
br label %53
53: ; preds = %71, %51
%54 = load i32, i32* %8
%55 = load i32, i32* %10
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %74
57: ; preds = %53
%58 = load i8*, i8** %11
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = load i8*, i8** %4
%64 = load i32, i32* %5
%65 = load i32, i32* %9
%66 = add nsw i32 %64, %65
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %63, i64 %67
store i8 %62, i8* %68
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %71
71: ; preds = %57
%72 = load i32, i32* %8
%73 = add nsw i32 %72, 1
store i32 %73, i32* %8
br label %53
74: ; preds = %53
%75 = load i8*, i8** %11
%76 = call i32 @free(i8* %75)
br label %77
77: ; preds = %74, %23
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
define void @strpack(i8* %0, i32 %1, i32 %2) {
%4 = sub i32 %2, %1
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %33
11: ; preds = %3
%12 = sext i32 %1 to i64
%13 = getelementptr i8, i8* %0, i64 %12
%14 = tail call i32 @strncpy(i8* %6, i8* %13, i32 %5)
%15 = tail call i32 @memset(i8* %13, i32 0, i32 %5)
br label %16
16: ; preds = %16, %11
%17 = phi i64 [ %21, %16 ], [ 0, %11 ]
%18 = getelementptr inbounds i8, i8* %6, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 32
%21 = add nuw i64 %17, 1
br i1 %20, label %16, label %22
22: ; preds = %16
%23 = trunc i64 %17 to i32
%24 = icmp slt i32 %4, %23
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = and i64 %17, 4294967295
%27 = getelementptr i8, i8* %6, i64 %26
%28 = sub i32 %4, %23
%29 = zext i32 %28 to i64
%30 = add nuw nsw i64 %29, 1
br label %31
31: ; preds = %25, %22
%32 = tail call i32 @free(i8* %6)
br label %33
33: ; preds = %31, %8
ret void
}