#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 *cmalloc(int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int insert(char **tab, char *file, char *dir, int *i, int n) {
  if (strlen(file) <= 2) {
    if (strncmp(file, "..", strlen(file)) == 0) {
      return 0;
    }
  }
  char **ptab = &tab[*i];
  char *chem = cmalloc((strlen(file) + strlen(dir) + 2) * sizeof(char));
  strncpy(chem, dir, strlen(dir) + 1);
  if (*i < n) {
    strncat(chem, file, strlen(file) + 1);
    *ptab = chem;
    *i = *i + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jg     11bc <insert+0x6c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe64(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11b7 <insert+0x67>
movl   $0x0,-0x4(%rbp)
jmp    1288 <insert+0x138>
jmp    11bc <insert+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <cmalloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
jge    1281 <insert+0x131>
mov    -0x40(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <strncat@plt>
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,(%rsp)
mov    %rsi,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jg     1196 <insert+0x46>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11f6 <insert+0xa6>
movslq (%r15),%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   1070 <cmalloc@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strncpy@plt>
cmp    %r12d,(%r15)
jge    11f6 <insert+0xa6>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <strncat@plt>
mov    (%rsp),%rax
mov    %rbp,(%rax,%r14,8)
addl   $0x1,(%r15)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
define i32 @insert(i8** %0, i8* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8**
%13 = alloca i8*
store i8** %0, i8*** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%14 = load i8*, i8** %8
%15 = call i32 @strlen(i8* %14)
%16 = icmp sle i32 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %5
%18 = load i8*, i8** %8
%19 = load i8*, i8** %8
%20 = call i32 @strlen(i8* %19)
%21 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 0, i32* %6
br label %65
24: ; preds = %17
br label %25
25: ; preds = %24, %5
%26 = load i8**, i8*** %7
%27 = load i32*, i32** %10
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
store i8** %30, i8*** %12
%31 = load i8*, i8** %8
%32 = call i32 @strlen(i8* %31)
%33 = load i8*, i8** %9
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %32, %34
%36 = add nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i8* @cmalloc(i32 %39)
store i8* %40, i8** %13
%41 = load i8*, i8** %13
%42 = load i8*, i8** %9
%43 = load i8*, i8** %9
%44 = call i32 @strlen(i8* %43)
%45 = add nsw i32 %44, 1
%46 = call i32 @strncpy(i8* %41, i8* %42, i32 %45)
%47 = load i32*, i32** %10
%48 = load i32, i32* %47
%49 = load i32, i32* %11
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %64
51: ; preds = %25
%52 = load i8*, i8** %13
%53 = load i8*, i8** %8
%54 = load i8*, i8** %8
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %55, 1
%57 = call i32 @strncat(i8* %52, i8* %53, i32 %56)
%58 = load i8*, i8** %13
%59 = load i8**, i8*** %12
store i8* %58, i8** %59
%60 = load i32*, i32** %10
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
%63 = load i32*, i32** %10
store i32 %62, i32* %63
br label %64
64: ; preds = %51, %25
store i32 0, i32* %6
br label %65
65: ; preds = %64, %23
%66 = load i32, i32* %6
ret i32 %66
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
define i32 @insert(i8** nocapture writeonly %0, i8* %1, i8* %2, i32* nocapture %3, i32 %4) {
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %1)
%10 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %8, %5
%13 = load i32, i32* %3
%14 = tail call i32 @strlen(i8* %1)
%15 = tail call i32 @strlen(i8* %2)
%16 = add i32 %14, 2
%17 = add i32 %16, %15
%18 = tail call i8* @cmalloc(i32 %17)
%19 = tail call i32 @strlen(i8* %2)
%20 = add nsw i32 %19, 1
%21 = tail call i32 @strncpy(i8* %18, i8* %2, i32 %20)
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, %4
br i1 %23, label %24, label %32
24: ; preds = %12
%25 = sext i32 %13 to i64
%26 = getelementptr inbounds i8*, i8** %0, i64 %25
%27 = tail call i32 @strlen(i8* %1)
%28 = add nsw i32 %27, 1
%29 = tail call i32 @strncat(i8* %18, i8* %1, i32 %28)
store i8* %18, i8** %26
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %32
32: ; preds = %12, %24, %8
ret i32 0
}