#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__ contains(char const, char *, size_t);
scalar_t__ has_valid_length(char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strcut(char *, unsigned int, int);
size_t strlen(char const *);
int semver_clean(const char *s, char *dest) {
  if (has_valid_length(s) == 0)
    return -1;
  int offset = 0;
  strcpy((char *)dest, s);
  size_t len = strlen(s);
  size_t mlen = strlen("0123456789"
                       "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                       "."
                       "-"
                       "+");
  for (unsigned int i = 0; i < len; i++) {
    if (contains(s[i],
                 "0123456789"
                 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                 "."
                 "-"
                 "+",
                 mlen) == 0) {
      strcut((char *)dest, i - offset, 1);
      offset++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<semver_clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <has_valid_length@plt>
cmp    $0x0,%rax
jne    117f <semver_clean+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <semver_clean+0xca>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x41,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%rax
jae    1213 <semver_clean+0xc3>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x30(%rbp),%rdx
lea    0xe2f(%rip),%rsi
movsbl %al,%edi
call   1050 <contains@plt>
cmp    $0x0,%rax
jne    1200 <semver_clean+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%esi
sub    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1070 <strcut@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1205 <semver_clean+0xb5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11af <semver_clean+0x5f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semver_clean>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <has_valid_length@plt>
test   %rax,%rax
je     11d9 <semver_clean+0x89>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11d5 <semver_clean+0x85>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xe71(%rip),%r12
xor    %ebp,%ebp
jmp    11a8 <semver_clean+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
cmp    %rbx,%r13
jbe    11d5 <semver_clean+0x85>
movsbl (%r15,%rbx,1),%edi
mov    $0x41,%edx
mov    %r12,%rsi
call   1050 <contains@plt>
test   %rax,%rax
jne    11a0 <semver_clean+0x50>
mov    %ebx,%esi
sub    %ebp,%esi
mov    %r14,%rdi
mov    $0x1,%edx
call   1070 <strcut@plt>
add    $0x1,%ebp
jmp    11a0 <semver_clean+0x50>
xor    %eax,%eax
jmp    11de <semver_clean+0x8e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-+\00"
define i32 @semver_clean(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i64 @has_valid_length(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %47
14: ; preds = %2
store i32 0, i32* %6
%15 = load i8*, i8** %5
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %7
store i64 65, i64* %8
store i32 0, i32* %9
br label %20
20: ; preds = %43, %14
%21 = load i32, i32* %9
%22 = zext i32 %21 to i64
%23 = load i64, i64* %7
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load i32, i32* %9
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = load i64, i64* %8
%32 = call i64 @contains(i8 signext %30, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i64 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %25
%35 = load i8*, i8** %5
%36 = load i32, i32* %9
%37 = load i32, i32* %6
%38 = sub i32 %36, %37
%39 = call i32 @strcut(i8* %35, i32 %38, i32 1)
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %42
42: ; preds = %34, %25
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add i32 %44, 1
store i32 %45, i32* %9
br label %20
46: ; preds = %20
store i32 0, i32* %3
br label %47
47: ; preds = %46, %13
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [66 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-+\00"
define i32 @semver_clean(i8* %0, i8* %1) {
%3 = tail call i64 @has_valid_length(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %1, i8* %0)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %5, %21
%10 = phi i64 [ %24, %21 ], [ 0, %5 ]
%11 = phi i32 [ %22, %21 ], [ 0, %5 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = tail call i64 @contains(i8 signext %13, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i64 65)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = trunc i64 %10 to i32
%18 = sub i32 %17, %11
%19 = tail call i32 @strcut(i8* %1, i32 %18, i32 1)
%20 = add nsw i32 %11, 1
br label %21
21: ; preds = %9, %16
%22 = phi i32 [ %20, %16 ], [ %11, %9 ]
%23 = add nuw nsw i64 %10, 1
%24 = and i64 %23, 4294967295
%25 = icmp ugt i64 %7, %24
br i1 %25, label %9, label %26
26: ; preds = %21, %5, %2
%27 = phi i32 [ -1, %2 ], [ 0, %5 ], [ 0, %21 ]
ret i32 %27
}