#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
char *apply_mod(char *, char const *, char const *, int *, int);
int /*<<< orphan*/ copy_str(char *, int, char const *const);
const char *apply_mods(const char path[], const char parent[], const char mod[],
                       int for_shell) {
  static char buf[4096];
  int napplied = 0;
  copy_str(buf, sizeof(buf), path);
  while (*mod != '\0') {
    int mod_len;
    const char *const p = apply_mod(buf, parent, mod, &mod_len, for_shell);
    if (p == NULL) {
      break;
    }
    copy_str(buf, sizeof(buf), p);
    mod += mod_len;
    napplied++;
  }
  return buf;
}


x86 assembly (clang, -O0):
<apply_mods>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdx
lea    0x2ef7(%rip),%rdi
mov    $0x1000,%esi
call   1030 <copy_str@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c7 <apply_mods+0xa7>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%r8d
lea    0x2eca(%rip),%rdi
lea    -0x24(%rbp),%rcx
call   1040 <apply_mod@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1193 <apply_mods+0x73>
jmp    11c7 <apply_mods+0xa7>
mov    -0x30(%rbp),%rdx
lea    0x2ea2(%rip),%rdi
mov    $0x1000,%esi
call   1030 <copy_str@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1153 <apply_mods+0x33>
lea    0x2e72(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_mods>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rdx
lea    0x2f01(%rip),%rdi
mov    $0x1000,%esi
call   1030 <copy_str@plt>
cmpb   $0x0,(%rbx)
je     1198 <apply_mods+0x78>
lea    0x2eeb(%rip),%rbp
lea    0xc(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r14d,%r8d
call   1040 <apply_mod@plt>
test   %rax,%rax
je     1198 <apply_mods+0x78>
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1030 <copy_str@plt>
movslq 0xc(%rsp),%rax
cmpb   $0x0,(%rbx,%rax,1)
lea    (%rbx,%rax,1),%rbx
jne    1160 <apply_mods+0x40>
lea    0x2ea1(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@apply_mods.buf = internal global [4096 x i8] zeroinitializer
define i8* @apply_mods(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
%12 = load i8*, i8** %5
%13 = call i32 @copy_str(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0), i32 4096, i8* %12)
br label %14
14: ; preds = %27, %4
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = call i8* @apply_mod(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0), i8* %20, i8* %21, i32* %10, i32 %22)
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %19
br label %36
27: ; preds = %19
%28 = load i8*, i8** %11
%29 = call i32 @copy_str(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0), i32 4096, i8* %28)
%30 = load i32, i32* %10
%31 = load i8*, i8** %7
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %7
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %14
36: ; preds = %26, %14
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@apply_mods.buf = internal global [4096 x i8] zeroinitializer
define i8* @apply_mods(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = tail call i32 @copy_str(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0), i32 4096, i8* %0)
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %4
%10 = bitcast i32* %5 to i8*
br label %11
11: ; preds = %9, %16
%12 = phi i8* [ %2, %9 ], [ %20, %16 ]
%13 = call i8* @apply_mod(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0), i8* %1, i8* %12, i32* %5, i32 %3)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
br label %23
16: ; preds = %11
%17 = call i32 @copy_str(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0), i32 4096, i8* %13)
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %12, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %16, %4, %15
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @apply_mods.buf, i64 0, i64 0)
}