#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 */
struct binary_exponential_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/
add_string_to_binary_exponential_buffer(void *,
                                        struct binary_exponential_buffer *);
scalar_t__ binary_exponential_buffer_data(struct binary_exponential_buffer *);
int /*<<< orphan*/
binary_exponential_buffer_increment(struct binary_exponential_buffer *, int);
unsigned int binary_exponential_buffer_size(struct binary_exponential_buffer *);
void add_filepath_macro(struct binary_exponential_buffer *output,
                        unsigned char *filename) {
  unsigned char *c = filename;
  while (*c) {
    if (*c == '/') {
      add_string_to_binary_exponential_buffer((void *)"_DIR_", output);
    } else if (*c == '.') {
      add_string_to_binary_exponential_buffer((void *)"_DOT_", output);
    } else if (*c == '-') {
      add_string_to_binary_exponential_buffer((void *)"_", output);
    } else {
      unsigned char *bu;
      unsigned int indx;
      indx = binary_exponential_buffer_size(output);
      binary_exponential_buffer_increment(output, 1);
      bu = (unsigned char *)binary_exponential_buffer_data(output);
      bu[indx] = *c;
    }
    c++;
  }
}


x86 assembly (clang, -O0):
<add_filepath_macro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1226 <add_filepath_macro+0xe6>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2f,%eax
jne    118a <add_filepath_macro+0x4a>
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1050 <add_string_to_binary_exponential_buffer@plt>
jmp    1215 <add_filepath_macro+0xd5>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2e,%eax
jne    11af <add_filepath_macro+0x6f>
mov    -0x8(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1050 <add_string_to_binary_exponential_buffer@plt>
jmp    1210 <add_filepath_macro+0xd0>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2d,%eax
jne    11d4 <add_filepath_macro+0x94>
mov    -0x8(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1050 <add_string_to_binary_exponential_buffer@plt>
jmp    120b <add_filepath_macro+0xcb>
mov    -0x8(%rbp),%rdi
call   1040 <binary_exponential_buffer_size@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x8(%rbp),%rdi
call   1060 <binary_exponential_buffer_data@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1210 <add_filepath_macro+0xd0>
jmp    1215 <add_filepath_macro+0xd5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <add_filepath_macro+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_filepath_macro>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeac(%rip),%r15
lea    0xea7(%rip),%r12
lea    0xe9a(%rip),%r13
jmp    117f <add_filepath_macro+0x3f>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <add_string_to_binary_exponential_buffer@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2d,%al
jle    11a0 <add_filepath_macro+0x60>
cmp    $0x2e,%al
je     1170 <add_filepath_macro+0x30>
cmp    $0x2f,%al
jne    11ab <add_filepath_macro+0x6b>
mov    %r13,%rdi
jmp    1173 <add_filepath_macro+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jne    11a7 <add_filepath_macro+0x67>
mov    %r15,%rdi
jmp    1173 <add_filepath_macro+0x33>
test   %al,%al
je     11d8 <add_filepath_macro+0x98>
mov    %r14,%rdi
call   1040 <binary_exponential_buffer_size@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    %r14,%rdi
call   1060 <binary_exponential_buffer_data@plt>
movzbl (%rbx),%ecx
mov    %ebp,%edx
mov    %cl,(%rax,%rdx,1)
add    $0x1,%rbx
jmp    117f <add_filepath_macro+0x3f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.binary_exponential_buffer = type { i32 }
@.str = [6 x i8] c"_DIR_\00"
@.str.1 = [6 x i8] c"_DOT_\00"
@.str.2 = [2 x i8] c"_\00"
define void @add_filepath_macro(%struct.binary_exponential_buffer* %0, i8* %1) {
%3 = alloca %struct.binary_exponential_buffer*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store %struct.binary_exponential_buffer* %0, %struct.binary_exponential_buffer** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
store i8* %8, i8** %5
br label %9
9: ; preds = %53, %2
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %56
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%20 = call i32 @add_string_to_binary_exponential_buffer(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.binary_exponential_buffer* %19)
br label %53
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 46
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%28 = call i32 @add_string_to_binary_exponential_buffer(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %struct.binary_exponential_buffer* %27)
br label %52
29: ; preds = %21
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 45
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%36 = call i32 @add_string_to_binary_exponential_buffer(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %struct.binary_exponential_buffer* %35)
br label %51
37: ; preds = %29
%38 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%39 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %38)
store i32 %39, i32* %7
%40 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%41 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %40, i32 1)
%42 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%43 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %42)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %6
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = load i8*, i8** %6
%48 = load i32, i32* %7
%49 = zext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
br label %51
51: ; preds = %37, %34
br label %52
52: ; preds = %51, %26
br label %53
53: ; preds = %52, %18
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %5
br label %9
56: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
@.str = [6 x i8] c"_DIR_\00"
@.str.1 = [6 x i8] c"_DOT_\00"
@.str.2 = [2 x i8] c"_\00"
define void @add_filepath_macro(%struct.binary_exponential_buffer* %0, i8* nocapture %1) {
br label %3
3: ; preds = %20, %2
%4 = phi i8* [ %1, %2 ], [ %21, %20 ]
%5 = load i8, i8* %4
switch i8 %5, label %12 [
i8 0, label %22
i8 47, label %6
i8 46, label %8
i8 45, label %10
]
6: ; preds = %3
%7 = tail call i32 @add_string_to_binary_exponential_buffer(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.binary_exponential_buffer* %0)
br label %20
8: ; preds = %3
%9 = tail call i32 @add_string_to_binary_exponential_buffer(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %struct.binary_exponential_buffer* %0)
br label %20
10: ; preds = %3
%11 = tail call i32 @add_string_to_binary_exponential_buffer(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %struct.binary_exponential_buffer* %0)
br label %20
12: ; preds = %3
%13 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %0)
%14 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %0, i32 1)
%15 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %0)
%16 = inttoptr i64 %15 to i8*
%17 = load i8, i8* %4
%18 = zext i32 %13 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 %17, i8* %19
br label %20
20: ; preds = %8, %12, %10, %6
%21 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
22: ; preds = %3
ret void
}