#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*/ append_exclude_dir_maybe(char *, char *);
int /*<<< orphan*/ column(char *, int, char *);
int count_columns(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
void build_find_string_buffer(char *destination, char *find_string,
                              char *exclude_dir) {
  char *ptr = destination;
  int i;
  int number_of_regular_expressions = count_columns(find_string);
  char column_buffer[512];
  if (number_of_regular_expressions == 0) {
    fprintf(stderr, "findsed() has no regular expressions!\n");
    exit(1);
  }
  ptr += sprintf(ptr, "find . -type f \\(");
  for (i = 0; i < number_of_regular_expressions; i++) {
    if (i) {
      ptr += sprintf(ptr, " -o");
    }
    column(column_buffer, i, find_string);
    ptr += sprintf(ptr, " -name '%s'", column_buffer);
  }
  sprintf(ptr, " \\) -xdev -print");
  append_exclude_dir_maybe(destination, exclude_dir);
}


x86 assembly (clang, -O0):
<build_find_string_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <count_columns@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11b4 <build_find_string_buffer+0x54>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    125f <build_find_string_buffer+0xff>
cmpl   $0x0,-0x24(%rbp)
je     1215 <build_find_string_buffer+0xb5>
mov    -0x20(%rbp),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <column@plt>
mov    -0x20(%rbp),%rdi
lea    -0x230(%rbp),%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11dd <build_find_string_buffer+0x7d>
mov    -0x20(%rbp),%rdi
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <append_exclude_dir_maybe@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_find_string_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <count_columns@plt>
test   %eax,%eax
je     1262 <build_find_string_buffer+0x102>
mov    %eax,%r13d
movups 0xe93(%rip),%xmm0
movups %xmm0,0x0(%rbp)
movw   $0x28,0x10(%rbp)
lea    0x11(%rbp),%rbx
test   %eax,%eax
mov    %r14,0x8(%rsp)
mov    %rbp,(%rsp)
jle    122f <build_find_string_buffer+0xcf>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1060 <column@plt>
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
movslq %eax,%r14
add    %rbx,%r14
cmp    $0x1,%r13d
je     1232 <build_find_string_buffer+0xd2>
mov    $0x1,%ebx
lea    0x10(%rsp),%rbp
nop
movl   $0x6f2d20,(%r14)
lea    0x3(%r14),%r15
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
call   1060 <column@plt>
mov    %r15,%rdi
lea    0xe27(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
cltq
add    %rax,%r14
add    $0x3,%r14
add    $0x1,%ebx
cmp    %ebx,%r13d
jne    11f0 <build_find_string_buffer+0x90>
jmp    1232 <build_find_string_buffer+0xd2>
mov    %rbx,%r14
movups 0xe0c(%rip),%xmm0
movups %xmm0,(%r14)
movb   $0x0,0x10(%r14)
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1030 <append_exclude_dir_maybe@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"findsed() has no regular expressions!\0A\00"
@.str.1 = [18 x i8] c"find . -type f \\(\00"
@.str.2 = [4 x i8] c" -o\00"
@.str.3 = [12 x i8] c" -name '%s'\00"
@.str.4 = [17 x i8] c" \\) -xdev -print\00"
define void @build_find_string_buffer(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
store i8* %11, i8** %7
%12 = load i8*, i8** %5
%13 = call i32 @count_columns(i8* %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = load i8*, i8** %7
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %7
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %7
store i32 0, i32* %8
br label %26
26: ; preds = %50, %20
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i8*, i8** %7
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%36 = load i8*, i8** %7
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %7
br label %39
39: ; preds = %33, %30
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%41 = load i32, i32* %8
%42 = load i8*, i8** %5
%43 = call i32 @column(i8* %40, i32 %41, i8* %42)
%44 = load i8*, i8** %7
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %7
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %7
br label %50
50: ; preds = %39
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %26
53: ; preds = %26
%54 = load i8*, i8** %7
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%56 = load i8*, i8** %4
%57 = load i8*, i8** %6
%58 = call i32 @append_exclude_dir_maybe(i8* %56, i8* %57)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"findsed() has no regular expressions!\0A\00"
@.str.1 = [18 x i8] c"find . -type f \\(\00"
@.str.3 = [12 x i8] c" -name '%s'\00"
@.str.4 = [17 x i8] c" \\) -xdev -print\00"
define void @build_find_string_buffer(i8* %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = tail call i32 @count_columns(i8* %1)
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %5, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(18) %0, i8* align 1 dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 18, i1 false)
%13 = getelementptr inbounds i8, i8* %0, i64 17
%14 = icmp sgt i32 %5, 0
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = call i32 @column(i8* %6, i32 0, i8* %1)
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = icmp eq i32 %5, 1
br i1 %20, label %32, label %21
21: ; preds = %15, %21
%22 = phi i8* [ %29, %21 ], [ %19, %15 ]
%23 = phi i32 [ %30, %21 ], [ 1, %15 ]
%24 = bitcast i8* %22 to i32*
store i32 7286048, i32* %24
%25 = getelementptr inbounds i8, i8* %22, i64 3
%26 = call i32 @column(i8* %6, i32 %23, i8* %1)
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = add nuw nsw i32 %23, 1
%31 = icmp eq i32 %30, %5
br i1 %31, label %32, label %21
32: ; preds = %21, %15, %12
%33 = phi i8* [ %13, %12 ], [ %19, %15 ], [ %29, %21 ]
%34 = call i32 @append_exclude_dir_maybe(i8* %0, i8* %2)
ret void
}