#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*/ free(char *);
scalar_t__ is_upper(char *);
int /*<<< orphan*/ isalpha(char);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *sanitize_string(char *s) {
  size_t len = strlen(s);
  int i = 0;
  if (s[0] == '(' && s[len - 1] == ')') {
    s[len - 1] = 0;
    s++;
  }
  if (is_upper(s)) {
    return NULL;
  }
  char *ret = malloc(len + 1);
  memset(ret, 0, len + 1);
  while (*s) {
    if ((*s == '\'') && (!strncmp(s + 1, "s", 1) || !strncmp(s + 1, "es", 2) ||
                         !strncmp(s + 1, "m", 1) || !strncmp(s + 1, "d", 1) ||
                         !strncmp(s + 1, "ll", 2))) {
      break;
    }
    if (*s == '.') {
      free(ret);
      return NULL;
    }
    if (!isalpha(*s)) {
      free(ret);
      return NULL;
    }
    ret[i++] = *s++;
  }
  ret[i] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<sanitize_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11d5 <sanitize_string+0x65>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
jne    11d5 <sanitize_string+0x65>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <is_upper@plt>
cmp    $0x0,%rax
je     11f5 <sanitize_string+0x85>
movq   $0x0,-0x8(%rbp)
jmp    1375 <sanitize_string+0x205>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1361 <sanitize_string+0x1f1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    12e5 <sanitize_string+0x175>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xdbc(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     12e0 <sanitize_string+0x170>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xd99(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     12e0 <sanitize_string+0x170>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xd7a(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     12e0 <sanitize_string+0x170>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xd5a(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     12e0 <sanitize_string+0x170>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
lea    0xd3a(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12e5 <sanitize_string+0x175>
jmp    1361 <sanitize_string+0x1f1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    130b <sanitize_string+0x19b>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1375 <sanitize_string+0x205>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%eax
jne    1336 <sanitize_string+0x1c6>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1375 <sanitize_string+0x205>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1219 <sanitize_string+0xa9>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %rax,%rbp
cmpb   $0x28,(%rbx)
jne    119b <sanitize_string+0x2b>
cmpb   $0x29,-0x1(%rbp,%rbx,1)
jne    119b <sanitize_string+0x2b>
movb   $0x0,-0x1(%rbx,%rbp,1)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <is_upper@plt>
test   %rax,%rax
jne    12b5 <sanitize_string+0x145>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %r13d,%r13d
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1060 <memset@plt>
lea    0xe2f(%rip),%r15
lea    0xe27(%rip),%r12
nopl   0x0(%rax)
movzbl (%rbx,%r13,1),%eax
cmp    $0x27,%al
je     1200 <sanitize_string+0x90>
test   %al,%al
je     12a3 <sanitize_string+0x133>
cmp    $0x2e,%al
jne    1285 <sanitize_string+0x115>
jmp    12ad <sanitize_string+0x13d>
xchg   %ax,%ax
lea    (%rbx,%r13,1),%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12a3 <sanitize_string+0x133>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12a3 <sanitize_string+0x133>
mov    %rbp,%rdi
lea    0xdc5(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12a3 <sanitize_string+0x133>
mov    %rbp,%rdi
lea    0xdaf(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12a3 <sanitize_string+0x133>
mov    %rbp,%rdi
lea    0xd99(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12a3 <sanitize_string+0x133>
movzbl (%rbx,%r13,1),%eax
cmp    $0x2e,%al
je     12ad <sanitize_string+0x13d>
movsbl %al,%edi
call   1080 <isalpha@plt>
test   %eax,%eax
je     12ad <sanitize_string+0x13d>
movzbl (%rbx,%r13,1),%eax
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
jmp    11e0 <sanitize_string+0x70>
mov    %r13d,%eax
movb   $0x0,(%r14,%rax,1)
jmp    12b8 <sanitize_string+0x148>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"s\00"
@.str.1 = [3 x i8] c"es\00"
@.str.2 = [2 x i8] c"m\00"
@.str.3 = [2 x i8] c"d\00"
@.str.4 = [3 x i8] c"ll\00"
define i8* @sanitize_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 40
br i1 %13, label %14, label %29
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = sub i64 %16, 1
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 41
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = load i64, i64* %4
%25 = sub i64 %24, 1
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
br label %29
29: ; preds = %22, %14, %1
%30 = load i8*, i8** %3
%31 = call i64 @is_upper(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i8* null, i8** %2
br label %108
34: ; preds = %29
%35 = load i64, i64* %4
%36 = add i64 %35, 1
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = load i64, i64* %4
%40 = add i64 %39, 1
%41 = call i32 @memset(i8* %38, i32 0, i64 %40)
br label %42
42: ; preds = %93, %34
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %102
46: ; preds = %42
%47 = load i8*, i8** %3
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 39
br i1 %50, label %51, label %77
51: ; preds = %46
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = call i32 @strncmp(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %76
56: ; preds = %51
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i32 @strncmp(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %76
61: ; preds = %56
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = call i32 @strncmp(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %76
66: ; preds = %61
%67 = load i8*, i8** %3
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = call i32 @strncmp(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load i8*, i8** %3
%73 = getelementptr inbounds i8, i8* %72, i64 1
%74 = call i32 @strncmp(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%75 = icmp ne i32 %74, 0
br i1 %75, label %77, label %76
76: ; preds = %71, %66, %61, %56, %51
br label %102
77: ; preds = %71, %46
%78 = load i8*, i8** %3
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 46
br i1 %81, label %82, label %85
82: ; preds = %77
%83 = load i8*, i8** %6
%84 = call i32 @free(i8* %83)
store i8* null, i8** %2
br label %108
85: ; preds = %77
%86 = load i8*, i8** %3
%87 = load i8, i8* %86
%88 = call i32 @isalpha(i8 signext %87)
%89 = icmp ne i32 %88, 0
br i1 %89, label %93, label %90
90: ; preds = %85
%91 = load i8*, i8** %6
%92 = call i32 @free(i8* %91)
store i8* null, i8** %2
br label %108
93: ; preds = %85
%94 = load i8*, i8** %3
%95 = getelementptr inbounds i8, i8* %94, i32 1
store i8* %95, i8** %3
%96 = load i8, i8* %94
%97 = load i8*, i8** %6
%98 = load i32, i32* %5
%99 = add nsw i32 %98, 1
store i32 %99, i32* %5
%100 = sext i32 %98 to i64
%101 = getelementptr inbounds i8, i8* %97, i64 %100
store i8 %96, i8* %101
br label %42
102: ; preds = %76, %42
%103 = load i8*, i8** %6
%104 = load i32, i32* %5
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %103, i64 %105
store i8 0, i8* %106
%107 = load i8*, i8** %6
store i8* %107, i8** %2
br label %108
108: ; preds = %102, %90, %82, %33
%109 = load i8*, i8** %2
ret i8* %109
}

LLVM IR (-O2):
@.str = [2 x i8] c"s\00"
@.str.1 = [3 x i8] c"es\00"
@.str.2 = [2 x i8] c"m\00"
@.str.3 = [2 x i8] c"d\00"
@.str.4 = [3 x i8] c"ll\00"
define i8* @sanitize_string(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 40
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = add i64 %2, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 41
br i1 %9, label %10, label %12
10: ; preds = %5
store i8 0, i8* %7
%11 = getelementptr inbounds i8, i8* %0, i64 1
br label %12
12: ; preds = %10, %5, %1
%13 = phi i8* [ %11, %10 ], [ %0, %5 ], [ %0, %1 ]
%14 = tail call i64 @is_upper(i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %60
16: ; preds = %12
%17 = add i64 %2, 1
%18 = tail call i8* @malloc(i64 %17)
%19 = tail call i32 @memset(i8* %18, i32 0, i64 %17)
br label %20
20: ; preds = %52, %16
%21 = phi i64 [ %55, %52 ], [ 0, %16 ]
%22 = phi i8* [ %53, %52 ], [ %13, %16 ]
%23 = load i8, i8* %22
switch i8 %23, label %42 [
i8 0, label %57
i8 39, label %24
]
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %22, i64 1
%26 = tail call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%27 = icmp eq i32 %26, 0
br i1 %27, label %57, label %28
28: ; preds = %24
%29 = tail call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%30 = icmp eq i32 %29, 0
br i1 %30, label %57, label %31
31: ; preds = %28
%32 = tail call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%33 = icmp eq i32 %32, 0
br i1 %33, label %57, label %34
34: ; preds = %31
%35 = tail call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%36 = icmp eq i32 %35, 0
br i1 %36, label %57, label %37
37: ; preds = %34
%38 = tail call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%39 = icmp eq i32 %38, 0
br i1 %39, label %57, label %40
40: ; preds = %37
%41 = load i8, i8* %22
br label %42
42: ; preds = %40, %20
%43 = phi i8 [ %41, %40 ], [ %23, %20 ]
%44 = icmp eq i8 %43, 46
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = tail call i32 @free(i8* %18)
br label %60
47: ; preds = %42
%48 = tail call i32 @isalpha(i8 signext %43)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = tail call i32 @free(i8* %18)
br label %60
52: ; preds = %47
%53 = getelementptr inbounds i8, i8* %22, i64 1
%54 = load i8, i8* %22
%55 = add nuw i64 %21, 1
%56 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 %54, i8* %56
br label %20
57: ; preds = %20, %24, %28, %31, %34, %37
%58 = and i64 %21, 4294967295
%59 = getelementptr inbounds i8, i8* %18, i64 %58
store i8 0, i8* %59
br label %60
60: ; preds = %45, %50, %57, %12
%61 = phi i8* [ null, %12 ], [ null, %45 ], [ null, %50 ], [ %18, %57 ]
ret i8* %61
}