#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*/ strcpy(char *, char const *);
char *strdup2(char *);
int /*<<< orphan*/ strlen(char const *);
char *strpbrk(char *, char *);
char *strstr(char *, char *);
char *gen_name_base_iso(const char *iso) {
  char id_arr[strlen(iso) + 1];
  char *id = id_arr;
  strcpy(id, iso);
  while (1) {
    char *last_slash = strpbrk(id, "/\\");
    if (last_slash)
      id = last_slash + 1;
    else
      break;
  }
  char *iso_loc = strstr(id, ".iso");
  if (iso_loc)
    iso_loc[0] = '\0';
  return strdup2(id);
}


x86 assembly (clang, -O0):
<gen_name_base_iso>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,%rsp
mov    %rcx,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    119f <gen_name_base_iso+0x4f>
mov    -0x20(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1060 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cf <gen_name_base_iso+0x7f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d4 <gen_name_base_iso+0x84>
jmp    11d9 <gen_name_base_iso+0x89>
jmp    119a <gen_name_base_iso+0x4a>
mov    -0x20(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ff <gen_name_base_iso+0xaf>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <strdup2@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_name_base_iso>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe78(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strpbrk@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
jne    1190 <gen_name_base_iso+0x40>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11be <gen_name_base_iso+0x6e>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <strdup2@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"/\\\00"
@.str.1 = [5 x i8] c".iso\00"
define i8* @gen_name_base_iso(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 %11
store i64 %11, i64* %4
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = load i8*, i8** %2
%16 = call i32 @strcpy(i8* %14, i8* %15)
br label %17
17: ; preds = %27, %1
br label %18
18: ; preds = %17
%19 = load i8*, i8** %5
%20 = call i8* @strpbrk(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %5
br label %27
26: ; preds = %18
br label %28
27: ; preds = %23
br label %17
28: ; preds = %26
%29 = load i8*, i8** %5
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 0, i8* %35
br label %36
36: ; preds = %33, %28
%37 = load i8*, i8** %5
%38 = call i8* @strdup2(i8* %37)
%39 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"/\\\00"
@.str.1 = [5 x i8] c".iso\00"
define i8* @gen_name_base_iso(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @strcpy(i8* %5, i8* %0)
br label %7
7: ; preds = %7, %1
%8 = phi i8* [ %5, %1 ], [ %11, %7 ]
%9 = call i8* @strpbrk(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %10, label %12, label %7
12: ; preds = %7
%13 = call i8* @strstr(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8 0, i8* %13
br label %16
16: ; preds = %15, %12
%17 = call i8* @strdup2(i8* %8)
ret i8* %17
}