#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 */
char *ftp2ext(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
void add_filters(char *filter, int *n, int nf, int ftp[]) {
  char buf[8];
  int i;
  sprintf(filter, "*.{");
  for (i = 0; (i < nf); i++) {
    sprintf(buf, "%s", ftp2ext(ftp[i]));
    if (*n > 0)
      strcat(filter, ",");
    strcat(filter, buf);
    (*n)++;
  }
  strcat(filter, "}");
}


x86 assembly (clang, -O0):
<add_filters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11dc <add_filters+0xac>
lea    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <ftp2ext@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11b6 <add_filters+0x86>
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1160 <add_filters+0x30>
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1040 <strcat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_filters>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
movl   $0x7b2e2a,(%rdi)
test   %edx,%edx
jle    11a1 <add_filters+0x71>
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %edx,%ebp
xor    %r13d,%r13d
mov    %rsp,%r12
jmp    1177 <add_filters+0x47>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
addl   $0x1,(%rbx)
add    $0x1,%r13
cmp    %r13,%rbp
je     11a1 <add_filters+0x71>
mov    (%r14,%r13,4),%edi
call   1040 <ftp2ext@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,(%rbx)
jle    1160 <add_filters+0x30>
mov    %r15,%rdi
lea    0xe66(%rip),%rsi
call   1050 <strcat@plt>
jmp    1160 <add_filters+0x30>
lea    0xe5a(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"*.{\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"}\00"
define void @add_filters(i8* %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [8 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%11 = load i8*, i8** %5
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
br label %13
13: ; preds = %39, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%19 = load i32*, i32** %8
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i8* @ftp2ext(i32 %23)
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %6
%27 = load i32, i32* %26
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = load i8*, i8** %5
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %29, %17
%33 = load i8*, i8** %5
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
br label %39
39: ; preds = %32
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %13
42: ; preds = %13
%43 = load i8*, i8** %5
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"}\00"
define void @add_filters(i8* %0, i32* nocapture %1, i32 %2, i32* nocapture %3) {
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%7 = bitcast i8* %0 to i32*
store i32 8072746, i32* %7
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %27
9: ; preds = %4
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %21
%12 = phi i64 [ 0, %9 ], [ %25, %21 ]
%13 = getelementptr inbounds i32, i32* %3, i64 %12
%14 = load i32, i32* %13
%15 = call i8* @ftp2ext(i32 %14)
%16 = call i8* @strcpy(i8* %6, i8* dereferenceable(1) %15)
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = call i32 @strcat(i8* %0, i8* %6)
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %1
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %27, label %11
27: ; preds = %21, %4
%28 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}