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


x86 assembly (clang, -O0):
<semver_clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <has_valid_length@plt>
cmp    $0x0,%rax
jne    116b <semver_clean+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <semver_clean+0xe6>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe81(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    121f <semver_clean+0xdf>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x28(%rbp),%rdx
lea    0xe4c(%rip),%rsi
movsbl %al,%edi
call   1040 <contains@plt>
cmp    $0x0,%rax
jne    1209 <semver_clean+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1060 <strcut@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11f1 <semver_clean+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <semver_clean+0xe6>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    120e <semver_clean+0xce>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1190 <semver_clean+0x50>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semver_clean>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1050 <has_valid_length@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11c2 <semver_clean+0x82>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11bf <semver_clean+0x7f>
mov    %rax,%rbp
xor    %ebx,%ebx
lea    0xe8c(%rip),%r12
jmp    1191 <semver_clean+0x51>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbp
add    $0xffffffffffffffff,%rbx
add    $0x1,%rbx
cmp    %rbp,%rbx
jae    11bf <semver_clean+0x7f>
movsbl (%r15,%rbx,1),%edi
mov    $0x41,%edx
mov    %r12,%rsi
call   1040 <contains@plt>
test   %rax,%rax
jne    1188 <semver_clean+0x48>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <strcut@plt>
cmp    $0xffffffff,%eax
jne    1180 <semver_clean+0x40>
jmp    11c2 <semver_clean+0x82>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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