#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__ strcmp(char *, char *);
size_t strlen(char *);
void clean_init(char *cg) {
  char *p;
  size_t cg_len = strlen(cg), init_len = strlen("/init.scope");
  if (cg_len < init_len)
    return;
  p = cg + cg_len - init_len;
  if (strcmp(p, "/init.scope") == 0) {
    if (p == cg)
      *(p + 1) = '\0';
    else
      *p = '\0';
  }
}


x86 assembly (clang, -O0):
<clean_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    0xec0(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    115c <clean_init+0x3c>
jmp    11b2 <clean_init+0x92>
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
xor    %ecx,%ecx
sub    -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b2 <clean_init+0x92>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11a6 <clean_init+0x86>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11ad <clean_init+0x8d>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b2 <clean_init+0x92>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_init>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0xb,%rax
jb     115c <clean_init+0x3c>
lea    (%rbx,%rax,1),%r14
add    $0xfffffffffffffff5,%r14
lea    0xebf(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    115c <clean_init+0x3c>
lea    0x1(%rbx),%rax
cmp    %rbx,%r14
cmovne %r14,%rax
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/init.scope\00"
define void @clean_init(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %4
%8 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i64 %8, i64* %5
%9 = load i64, i64* %4
%10 = load i64, i64* %5
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %1
br label %33
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = load i64, i64* %4
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i64, i64* %5
%18 = sub i64 0, %17
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %13
%24 = load i8*, i8** %3
%25 = load i8*, i8** %2
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 0, i8* %29
br label %32
30: ; preds = %23
%31 = load i8*, i8** %3
store i8 0, i8* %31
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %12, %32, %13
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"/init.scope\00"
define void @clean_init(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp ult i64 %2, 11
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 %2
%6 = getelementptr inbounds i8, i8* %5, i64 -11
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = icmp eq i8* %6, %0
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = select i1 %10, i8* %11, i8* %6
store i8 0, i8* %12
br label %13
13: ; preds = %9, %4, %1
ret void
}