#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(char);
char *malloc(scalar_t__);
scalar_t__ strlen(char *);
int /*<<< orphan*/ tolower(char);
__attribute__((unused)) void sanitize_image_name(char **outp, char *in) {
  if (!in) {
    *outp = NULL;
    return;
  }
  char *out = malloc(strlen(in) + 1);
  *outp = out;
  bool dot = false, dash = false;
  for (; *in; in++) {
    if (*in == '.') {
      dot = true;
      continue;
    }
    if (*in != '+' && !isalnum(*in)) {
      dash = true;
      continue;
    }
    if (dash)
      *out++ = '-';
    else if (dot)
      *out++ = '.';
    dash = false;
    dot = false;
    *out++ = tolower(*in);
  }
  *out = 0;
}


x86 assembly (clang, -O0):
<sanitize_image_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <sanitize_image_name+0x2b>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    127e <sanitize_image_name+0x13e>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1277 <sanitize_image_name+0x137>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11c6 <sanitize_image_name+0x86>
movl   $0x1,-0x1c(%rbp)
jmp    1266 <sanitize_image_name+0x126>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     11f7 <sanitize_image_name+0xb7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    11f7 <sanitize_image_name+0xb7>
movl   $0x1,-0x20(%rbp)
jmp    1266 <sanitize_image_name+0x126>
cmpl   $0x0,-0x20(%rbp)
je     1218 <sanitize_image_name+0xd8>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
jmp    1239 <sanitize_image_name+0xf9>
cmpl   $0x0,-0x1c(%rbp)
je     1234 <sanitize_image_name+0xf4>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2e,(%rax)
jmp    1239 <sanitize_image_name+0xf9>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119d <sanitize_image_name+0x5d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_image_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
test   %rsi,%rsi
je     11e4 <sanitize_image_name+0xa4>
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,(%r15)
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    118a <sanitize_image_name+0x4a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%r15d
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2b,%al
je     11a5 <sanitize_image_name+0x65>
cmp    $0x2e,%al
je     1180 <sanitize_image_name+0x40>
test   %al,%al
je     11de <sanitize_image_name+0x9e>
movsbl %al,%edi
call   1040 <isalnum@plt>
test   %eax,%eax
je     11d3 <sanitize_image_name+0x93>
mov    $0x2d,%al
test   %ebp,%ebp
jne    11b2 <sanitize_image_name+0x72>
mov    $0x2e,%al
test   %r15d,%r15d
je     11b9 <sanitize_image_name+0x79>
mov    %al,(%r14)
add    $0x1,%r14
movsbl (%rbx),%edi
call   1050 <tolower@plt>
mov    %al,(%r14)
add    $0x1,%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
add    $0x1,%rbx
jmp    118a <sanitize_image_name+0x4a>
mov    $0x1,%ebp
add    $0x1,%rbx
jmp    118a <sanitize_image_name+0x4a>
movb   $0x0,(%r14)
jmp    11eb <sanitize_image_name+0xab>
movq   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sanitize_image_name(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = load i8**, i8*** %3
store i8* null, i8** %11
br label %65
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8**, i8*** %3
store i8* %17, i8** %18
store i32 0, i32* %6
store i32 0, i32* %7
br label %19
19: ; preds = %60, %12
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %63
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 46
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %6
br label %60
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 43
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = call i32 @isalnum(i8 signext %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %34
store i32 1, i32* %7
br label %60
40: ; preds = %34, %29
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
store i8 45, i8* %44
br label %53
46: ; preds = %40
%47 = load i32, i32* %6
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %5
store i8 46, i8* %50
br label %52
52: ; preds = %49, %46
br label %53
53: ; preds = %52, %43
store i32 0, i32* %7
store i32 0, i32* %6
%54 = load i8*, i8** %4
%55 = load i8, i8* %54
%56 = call i32 @tolower(i8 signext %55)
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %5
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %5
store i8 %57, i8* %58
br label %60
60: ; preds = %53, %39, %28
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %4
br label %19
63: ; preds = %19
%64 = load i8*, i8** %5
store i8 0, i8* %64
br label %65
65: ; preds = %63, %10
ret void
}

LLVM IR (-O2):
define void @sanitize_image_name(i8** nocapture writeonly %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %5
4: ; preds = %2
store i8* null, i8** %0
br label %37
5: ; preds = %2
%6 = tail call i64 @strlen(i8* %1)
%7 = add nsw i64 %6, 1
%8 = tail call i8* @malloc(i64 %7)
store i8* %8, i8** %0
br label %9
9: ; preds = %31, %5
%10 = phi i8* [ %1, %5 ], [ %35, %31 ]
%11 = phi i8* [ %8, %5 ], [ %32, %31 ]
%12 = phi i32 [ 0, %5 ], [ %33, %31 ]
%13 = phi i32 [ 0, %5 ], [ %34, %31 ]
%14 = load i8, i8* %10
switch i8 %14, label %15 [
i8 0, label %36
i8 46, label %31
i8 43, label %18
]
15: ; preds = %9
%16 = tail call i32 @isalnum(i8 signext %14)
%17 = icmp eq i32 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %9, %15
%19 = icmp eq i32 %13, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = icmp eq i32 %12, 0
br i1 %21, label %25, label %22
22: ; preds = %20, %18
%23 = phi i8 [ 45, %18 ], [ 46, %20 ]
%24 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %23, i8* %11
br label %25
25: ; preds = %22, %20
%26 = phi i8* [ %11, %20 ], [ %24, %22 ]
%27 = load i8, i8* %10
%28 = tail call i32 @tolower(i8 signext %27)
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %29, i8* %26
br label %31
31: ; preds = %15, %9, %25
%32 = phi i8* [ %30, %25 ], [ %11, %9 ], [ %11, %15 ]
%33 = phi i32 [ 0, %25 ], [ 1, %9 ], [ %12, %15 ]
%34 = phi i32 [ 0, %25 ], [ %13, %9 ], [ 1, %15 ]
%35 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
36: ; preds = %9
store i8 0, i8* %11
br label %37
37: ; preds = %36, %4
ret void
}