#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 */
scalar_t__ emalloc(int);
int /*<<< orphan*/ isalnum(char);
int strlen(char *);
char *strncpy(char *, char *, int);
char *cleanWordEdges(char *word) {
  int l1, l2;
  char *word2 = NULL;
  while (!isalnum(*word) && *word != '\0') {
    word++;
  }
  l1 = strlen(word);
  l2 = l1;
  while (l2 > 0 && !isalnum(word[l2 - 1])) {
    l2--;
  }
  if (l2 < l1) {
    word2 = (char *)emalloc((l2 + 1) * sizeof(char));
    word2 = strncpy(word2, word, l2);
    return word2;
  } else {
    return word;
  }
}


x86 assembly (clang, -O0):
<cleanWordEdges>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    1180 <cleanWordEdges+0x40>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1190 <cleanWordEdges+0x50>
jmp    11a1 <cleanWordEdges+0x61>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1154 <cleanWordEdges+0x14>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x22(%rbp)
jle    11e3 <cleanWordEdges+0xa3>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11f3 <cleanWordEdges+0xb3>
jmp    1201 <cleanWordEdges+0xc1>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11b3 <cleanWordEdges+0x73>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1245 <cleanWordEdges+0x105>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <emalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124d <cleanWordEdges+0x10d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanWordEdges>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
movsbl (%rdi),%edi
xchg   %ax,%ax
call   1050 <isalnum@plt>
test   %eax,%eax
jne    116c <cleanWordEdges+0x2c>
cmpb   $0x0,(%r12)
je     116c <cleanWordEdges+0x2c>
movsbl 0x1(%r12),%edi
add    $0x1,%r12
jmp    1150 <cleanWordEdges+0x10>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
xor    %r14d,%r14d
test   %eax,%eax
cmovs  %eax,%r14d
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %ebx,%ebx
jle    11ad <cleanWordEdges+0x6d>
movsbl -0x1(%r12,%rbx,1),%edi
add    $0xffffffffffffffff,%rbx
call   1050 <isalnum@plt>
test   %eax,%eax
je     1190 <cleanWordEdges+0x50>
add    $0x1,%ebx
mov    %ebx,%r14d
cmp    %r15d,%r14d
jge    11d4 <cleanWordEdges+0x94>
lea    0x1(%r14),%edi
call   1060 <emalloc@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strncpy@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @cleanWordEdges(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %6
br label %7
7: ; preds = %19, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = call i32 @isalnum(i8 signext %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %12, %7
%18 = phi i1 [ false, %7 ], [ %16, %12 ]
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %7
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
store i32 %25, i32* %5
br label %26
26: ; preds = %41, %22
%27 = load i32, i32* %5
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @isalnum(i8 signext %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br label %39
39: ; preds = %29, %26
%40 = phi i1 [ false, %26 ], [ %38, %29 ]
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %26
44: ; preds = %39
%45 = load i32, i32* %5
%46 = load i32, i32* %4
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 1
%53 = trunc i64 %52 to i32
%54 = call i64 @emalloc(i32 %53)
%55 = inttoptr i64 %54 to i8*
store i8* %55, i8** %6
%56 = load i8*, i8** %6
%57 = load i8*, i8** %3
%58 = load i32, i32* %5
%59 = call i8* @strncpy(i8* %56, i8* %57, i32 %58)
store i8* %59, i8** %6
%60 = load i8*, i8** %6
store i8* %60, i8** %2
br label %63
61: ; preds = %44
%62 = load i8*, i8** %3
store i8* %62, i8** %2
br label %63
63: ; preds = %61, %48
%64 = load i8*, i8** %2
ret i8* %64
}

LLVM IR (-O2):
define i8* @cleanWordEdges(i8* %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @isalnum(i8 signext %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1, %9
%6 = phi i8* [ %10, %9 ], [ %0, %1 ]
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %10
%12 = tail call i32 @isalnum(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %5, label %14
14: ; preds = %5, %9, %1
%15 = phi i8* [ %0, %1 ], [ %10, %9 ], [ %6, %5 ]
%16 = tail call i32 @strlen(i8* %15)
%17 = zext i32 %16 to i64
%18 = call i32 @llvm.smin.i32(i32 %16, i32 0)
br label %19
19: ; preds = %23, %14
%20 = phi i64 [ %24, %23 ], [ %17, %14 ]
%21 = trunc i64 %20 to i32
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = add nsw i64 %20, -1
%25 = getelementptr inbounds i8, i8* %15, i64 %24
%26 = load i8, i8* %25
%27 = tail call i32 @isalnum(i8 signext %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %19, label %29
29: ; preds = %23
%30 = trunc i64 %20 to i32
br label %31
31: ; preds = %19, %29
%32 = phi i32 [ %30, %29 ], [ %18, %19 ]
%33 = icmp slt i32 %32, %16
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = add nsw i32 %32, 1
%36 = tail call i64 @emalloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
%38 = tail call i8* @strncpy(i8* %37, i8* %15, i32 %32)
br label %39
39: ; preds = %31, %34
%40 = phi i8* [ %38, %34 ], [ %15, %31 ]
ret i8* %40
}