#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 *, int, 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, (int)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    1228 <semver_clean+0xe8>
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    1221 <semver_clean+0xe1>
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    120b <semver_clean+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    $0x1,%edx
call   1060 <strcut@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11f3 <semver_clean+0xb3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1228 <semver_clean+0xe8>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1210 <semver_clean+0xd0>
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     11c1 <semver_clean+0x81>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11be <semver_clean+0x7e>
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    11be <semver_clean+0x7e>
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    %ebx,%esi
mov    $0x1,%edx
call   1060 <strcut@plt>
cmp    $0xffffffff,%eax
jne    1180 <semver_clean+0x40>
jmp    11c1 <semver_clean+0x81>
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 %46
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 = %42, %12
%17 = load i64, i64* %4
%18 = load i64, i64* %5
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %45
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 %41
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load i64, i64* %4
%31 = trunc i64 %30 to i32
%32 = call i32 @strcut(i8* %29, i32 %31, i32 1)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 -1, i32* %2
br label %46
36: ; preds = %28
%37 = load i64, i64* %5
%38 = add i64 %37, -1
store i64 %38, i64* %5
%39 = load i64, i64* %4
%40 = add i64 %39, -1
store i64 %40, i64* %4
br label %41
41: ; preds = %36, %20
br label %42
42: ; preds = %41
%43 = load i64, i64* %4
%44 = add i64 %43, 1
store i64 %44, i64* %4
br label %16
45: ; preds = %16
store i32 0, i32* %2
br label %46
46: ; preds = %45, %35, %11
%47 = load i32, i32* %2
ret i32 %47
}

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 %26, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %4, %21
%8 = phi i64 [ %24, %21 ], [ 0, %4 ]
%9 = phi i64 [ %22, %21 ], [ %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 %21
14: ; preds = %7
%15 = trunc i64 %8 to i32
%16 = tail call i32 @strcut(i8* %0, i32 %15, i32 1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %26, label %18
18: ; preds = %14
%19 = add i64 %9, -1
%20 = add i64 %8, -1
br label %21
21: ; preds = %7, %18
%22 = phi i64 [ %19, %18 ], [ %9, %7 ]
%23 = phi i64 [ %20, %18 ], [ %8, %7 ]
%24 = add i64 %23, 1
%25 = icmp ult i64 %24, %22
br i1 %25, label %7, label %26
26: ; preds = %14, %21, %4, %1
%27 = phi i32 [ -1, %1 ], [ 0, %4 ], [ -1, %14 ], [ 0, %21 ]
ret i32 %27
}