#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*/ isalnum(unsigned char);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void strip_beg_end(char *s) {
  int beg, len;
  beg = 0;
  while (!isalnum((unsigned char)(s[beg])))
    beg++;
  len = (int)strlen(s) - 1;
  while (!isalnum((unsigned char)(s[len])))
    len--;
  strncpy(s, s + beg, len - beg + 1);
  s[len - beg + 1] = (char)0;
  return;
}


x86 assembly (clang, -O0):
<strip_beg_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1169 <strip_beg_end+0x39>
jmp    1177 <strip_beg_end+0x47>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <strip_beg_end+0x13>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ac <strip_beg_end+0x7c>
jmp    11ba <strip_beg_end+0x8a>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <strip_beg_end+0x56>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%edx
sub    -0xc(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_beg_end>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0xfffffffe,%r12d
mov    $0xffffffffffffffff,%r15
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%r14,%r15,1),%edi
call   1050 <isalnum@plt>
add    $0x1,%r12d
add    $0x1,%r15
test   %eax,%eax
je     1150 <strip_beg_end+0x20>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rbx
add    $0xffffffffffffffff,%rbx
mov    %eax,%ebp
sub    %r12d,%ebp
xchg   %ax,%ax
movzbl (%rbx),%edi
call   1050 <isalnum@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %eax,%eax
je     1180 <strip_beg_end+0x50>
mov    %r15d,%esi
add    %r14,%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @strip_beg_end(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %14, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = call i32 @isalnum(i8 zeroext %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %17
14: ; preds = %5
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %5
17: ; preds = %5
%18 = load i8*, i8** %2
%19 = call i64 @strlen(i8* %18)
%20 = trunc i64 %19 to i32
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %4
br label %22
22: ; preds = %31, %17
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @isalnum(i8 zeroext %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %22
34: ; preds = %22
%35 = load i8*, i8** %2
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i32, i32* %4
%41 = load i32, i32* %3
%42 = sub nsw i32 %40, %41
%43 = add nsw i32 %42, 1
%44 = call i32 @strncpy(i8* %35, i8* %39, i32 %43)
%45 = load i8*, i8** %2
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = sub nsw i32 %46, %47
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %45, i64 %50
store i8 0, i8* %51
ret void
}

LLVM IR (-O2):
define void @strip_beg_end(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %8, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i32 @isalnum(i8 zeroext %5)
%7 = icmp eq i32 %6, 0
%8 = add nuw i64 %3, 1
br i1 %7, label %2, label %9
9: ; preds = %2
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = shl i64 %10, 32
%12 = ashr exact i64 %11, 32
br label %13
13: ; preds = %13, %9
%14 = phi i64 [ %15, %13 ], [ %12, %9 ]
%15 = add nsw i64 %14, -1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @isalnum(i8 zeroext %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %13, label %20
20: ; preds = %13
%21 = trunc i64 %3 to i32
%22 = trunc i64 %15 to i32
%23 = and i64 %3, 4294967295
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = sub nsw i32 %22, %21
%26 = add nsw i32 %25, 1
%27 = tail call i32 @strncpy(i8* %0, i8* %24, i32 %26)
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret void
}