#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 *construct_insert(char *, char **, char **);
int /*<<< orphan*/ exec_nonquery(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
char *resolve_ambig(char *);
char *strdup(char *);
char *strtok(char *, char *);
void add_link_files(char *id, char *add) {
  if (add != NULL) {
    char *aux = strdup(add);
    char *temp = strtok(aux, ",");
    char *insert = NULL;
    while (temp != NULL) {
      char *file_path = resolve_ambig(temp);
      if (file_path != NULL) {
        insert = NULL;
        char *fields[] = {"RUTA_ARCHIVO_ASOC", "ID_ASOC", 0};
        char *values[] = {file_path, id, 0};
        insert = construct_insert("GP_ASOCIACIONES", fields, values);
        exec_nonquery(insert);
        printf("+ Asociated file %s\n", file_path);
        free(file_path);
        free(insert);
        temp = strtok(NULL, ",");
      } else {
        return;
      }
    }
  }
}


x86 assembly (clang, -O0):
<add_link_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1283 <add_link_files+0x113>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     127e <add_link_files+0x10e>
mov    -0x20(%rbp),%rdi
call   1040 <resolve_ambig@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1274 <add_link_files+0x104>
movq   $0x0,-0x28(%rbp)
mov    0x2c1a(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c17(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c14(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x60(%rbp)
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xdf5(%rip),%rdi
call   1080 <construct_insert@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <exec_nonquery@plt>
mov    -0x30(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1279 <add_link_files+0x109>
jmp    1283 <add_link_files+0x113>
jmp    11b4 <add_link_files+0x44>
jmp    1283 <add_link_files+0x113>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_link_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %rsi,%rsi
je     1247 <add_link_files+0xd7>
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1090 <strdup@plt>
lea    0xe67(%rip),%rsi
mov    %rax,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     1247 <add_link_files+0xd7>
mov    %rsp,%r12
lea    0xe78(%rip),%r13
lea    0xe45(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1040 <resolve_ambig@plt>
test   %rax,%rax
je     1247 <add_link_files+0xd7>
mov    %rax,%r14
mov    0x2c39(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0x2c1d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe1b(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    %r12,%rdx
call   1080 <construct_insert@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <exec_nonquery@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    11c0 <add_link_files+0x50>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [18 x i8] c"RUTA_ARCHIVO_ASOC\00"
@.str.2 = [8 x i8] c"ID_ASOC\00"
@__const.add_link_files.fields = [3 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [16 x i8] c"GP_ASOCIACIONES\00"
@.str.4 = [21 x i8] c"+ Asociated file %s\0A\00"
define void @add_link_files(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i8*]
%10 = alloca [3 x i8*]
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %48
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %6
store i8* null, i8** %7
br label %18
18: ; preds = %46, %13
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %47
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = call i8* @resolve_ambig(i8* %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %45
26: ; preds = %21
store i8* null, i8** %7
%27 = bitcast [3 x i8*]* %9 to i8*
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
%29 = load i8*, i8** %8
store i8* %29, i8** %28
%30 = getelementptr inbounds i8*, i8** %28, i64 1
%31 = load i8*, i8** %3
store i8* %31, i8** %30
%32 = getelementptr inbounds i8*, i8** %30, i64 1
store i8* null, i8** %32
%33 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
%34 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
%35 = call i8* @construct_insert(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %33, i8** %34)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = call i32 @exec_nonquery(i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
%44 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %44, i8** %6
br label %46
45: ; preds = %21
br label %48
46: ; preds = %26
br label %18
47: ; preds = %18
br label %48
48: ; preds = %45, %47, %2
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [18 x i8] c"RUTA_ARCHIVO_ASOC\00"
@.str.2 = [8 x i8] c"ID_ASOC\00"
@__const.add_link_files.fields = [3 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [16 x i8] c"GP_ASOCIACIONES\00"
@.str.4 = [21 x i8] c"+ Asociated file %s\0A\00"
define void @add_link_files(i8* %0, i8* %1) {
%3 = alloca [3 x i8*]
%4 = alloca [3 x i8*]
%5 = icmp eq i8* %1, null
br i1 %5, label %29, label %6
6: ; preds = %2
%7 = tail call i8* @strdup(i8* %1)
%8 = tail call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %29, label %10
10: ; preds = %6
%11 = bitcast [3 x i8*]* %3 to i8*
%12 = bitcast [3 x i8*]* %4 to i8*
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
br label %17
17: ; preds = %10, %21
%18 = phi i8* [ %8, %10 ], [ %27, %21 ]
%19 = call i8* @resolve_ambig(i8* %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %29, label %21
21: ; preds = %17
store i8* %19, i8** %13
store i8* %0, i8** %14
store i8* null, i8** %15
%22 = call i8* @construct_insert(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %16, i8** %13)
%23 = call i32 @exec_nonquery(i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%25 = call i32 @free(i8* %19)
%26 = call i32 @free(i8* %22)
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %17
29: ; preds = %21, %17, %6, %2
ret void
}