#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*/ lib_free(char *);
char *lib_malloc(unsigned int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
void autostart_disk_cook_name(char **name) {
  unsigned int pos;
  pos = 0;
  while ((*name)[pos] != '\0') {
    if (((unsigned char)((*name)[pos])) == 0xa0) {
      char *ptr;
      ptr = lib_malloc(pos + 1);
      memcpy(ptr, *name, pos);
      ptr[pos] = '\0';
      lib_free(*name);
      *name = ptr;
      break;
    }
    pos++;
  }
}


x86 assembly (clang, -O0):
<autostart_disk_cook_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ca <autostart_disk_cook_name+0x9a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0xc(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0xa0,%eax
jne    11bc <autostart_disk_cook_name+0x8c>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <lib_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <lib_free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ca <autostart_disk_cook_name+0x9a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <autostart_disk_cook_name+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<autostart_disk_cook_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rax
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%ebx
movzbl (%rax,%rbx,1),%ecx
test   %cl,%cl
je     1191 <autostart_disk_cook_name+0x61>
cmp    $0xa0,%cl
je     1166 <autostart_disk_cook_name+0x36>
add    $0x1,%r12d
jmp    1150 <autostart_disk_cook_name+0x20>
lea    0x1(%r12),%edi
call   1030 <lib_malloc@plt>
mov    %rax,%r15
mov    (%r14),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    (%r14),%rdi
call   1040 <lib_free@plt>
mov    %r15,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @autostart_disk_cook_name(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i8*
store i8** %0, i8*** %2
store i32 0, i32* %3
br label %5
5: ; preds = %41, %1
%6 = load i8**, i8*** %2
%7 = load i8*, i8** %6
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %44
14: ; preds = %5
%15 = load i8**, i8*** %2
%16 = load i8*, i8** %15
%17 = load i32, i32* %3
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 160
br i1 %22, label %23, label %41
23: ; preds = %14
%24 = load i32, i32* %3
%25 = add i32 %24, 1
%26 = call i8* @lib_malloc(i32 %25)
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = load i8**, i8*** %2
%29 = load i8*, i8** %28
%30 = load i32, i32* %3
%31 = call i32 @memcpy(i8* %27, i8* %29, i32 %30)
%32 = load i8*, i8** %4
%33 = load i32, i32* %3
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8**, i8*** %2
%37 = load i8*, i8** %36
%38 = call i32 @lib_free(i8* %37)
%39 = load i8*, i8** %4
%40 = load i8**, i8*** %2
store i8* %39, i8** %40
br label %44
41: ; preds = %14
%42 = load i32, i32* %3
%43 = add i32 %42, 1
store i32 %43, i32* %3
br label %5
44: ; preds = %23, %5
ret void
}

LLVM IR (-O2):
define void @autostart_disk_cook_name(i8** nocapture %0) {
%2 = load i8*, i8** %0
br label %3
3: ; preds = %17, %1
%4 = phi i32 [ 0, %1 ], [ %18, %17 ]
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %17 [
i8 0, label %19
i8 -96, label %8
]
8: ; preds = %3
%9 = zext i32 %4 to i64
%10 = add i32 %4, 1
%11 = tail call i8* @lib_malloc(i32 %10)
%12 = load i8*, i8** %0
%13 = tail call i32 @memcpy(i8* %11, i8* %12, i32 %4)
%14 = getelementptr inbounds i8, i8* %11, i64 %9
store i8 0, i8* %14
%15 = load i8*, i8** %0
%16 = tail call i32 @lib_free(i8* %15)
store i8* %11, i8** %0
br label %19
17: ; preds = %3
%18 = add i32 %4, 1
br label %3
19: ; preds = %3, %8
ret void
}