#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 *_and_(char *, char *);
char *cond(char *, char *, char *);
char *construct_delete(char *, int /*<<< orphan*/);
char *construct_query(char **, int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int /*<<< orphan*/);
char *count(char *);
int exec_int_scalarquery(char *);
int /*<<< orphan*/ exec_nonquery(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ from(char *);
int /*<<< orphan*/ printf(char *, char *);
char *resolve_ambig(char *);
char *strdup(char *);
char *strtok(char *, char *);
int /*<<< orphan*/ where(char *);
void rm_link_files(char *id, char *rm) {
  if (rm != NULL) {
    char *aux = strdup(rm);
    char *temp = strtok(aux, ",");
    char *delete = NULL;
    while (temp != NULL) {
      char *file_path = resolve_ambig(temp);
      if (file_path != NULL) {
        delete = NULL;
        char *c1 = cond("RUTA_ARCHIVO_ASOC", "=", file_path);
        char *c2 = cond("ID_ASOC", "=", id);
        delete = construct_delete("GP_ASOCIACIONES", where(_and_(c1, c2)));
        exec_nonquery(delete);
        free(c2);
        free(c1);
        printf("- Deasociated file %s\n", file_path);
        char *check_query = NULL;
        char *f_count = count("RUTA_ARCHIVO_ASOC");
        char *f[] = {f_count, 0};
        check_query = construct_query(
            f, from("GP_ASOCIACIONES"),
            where(cond("RUTA_ARCHIVO_ASOC", "=", file_path)), 0, 0);
        int num = exec_int_scalarquery(check_query);
        if (!num) {
          char *clean_query = NULL;
          clean_query = construct_delete(
              "GP_ARCHIVO", where(cond("RUTA_ARCHIVO", "=", file_path)));
          exec_nonquery(clean_query);
          free(clean_query);
        }
        free(f_count);
        free(file_path);
        free(check_query);
        free(delete);
        temp = strtok(NULL, ",");
      } else {
        return;
      }
    }
    free(aux);
  }
}


x86 assembly (clang, -O0):
<rm_link_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1401 <rm_link_files+0x221>
mov    -0x10(%rbp),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     13f8 <rm_link_files+0x218>
mov    -0x20(%rbp),%rdi
call   1050 <resolve_ambig@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     13ee <rm_link_files+0x20e>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rdx
lea    0xda5(%rip),%rdi
lea    0xdb0(%rip),%rsi
call   1060 <cond@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xd9e(%rip),%rdi
lea    0xd95(%rip),%rsi
call   1060 <cond@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10d0 <_and_@plt>
mov    %rax,%rdi
call   1080 <where@plt>
mov    %eax,%esi
lea    0xd78(%rip),%rdi
call   1090 <construct_delete@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <exec_nonquery@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rsi
lea    0xd59(%rip),%rdi
call   1070 <printf@plt>
movq   $0x0,-0x48(%rbp)
lea    0xd19(%rip),%rdi
call   1030 <count@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    0xd0d(%rip),%rdi
call   10a0 <from@plt>
mov    %eax,-0x74(%rbp)
mov    -0x30(%rbp),%rdx
lea    0xcde(%rip),%rdi
lea    0xce9(%rip),%rsi
call   1060 <cond@plt>
mov    %rax,%rdi
call   1080 <where@plt>
mov    -0x80(%rbp),%rdi
mov    -0x74(%rbp),%esi
mov    %eax,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1100 <construct_query@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10c0 <exec_int_scalarquery@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    13b1 <rm_link_files+0x1d1>
movq   $0x0,-0x70(%rbp)
mov    -0x30(%rbp),%rdx
lea    0xcd7(%rip),%rdi
lea    0xc94(%rip),%rsi
call   1060 <cond@plt>
mov    %rax,%rdi
call   1080 <where@plt>
mov    %eax,%esi
lea    0xcaf(%rip),%rdi
call   1090 <construct_delete@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
call   10b0 <exec_nonquery@plt>
mov    -0x70(%rbp),%rdi
call   1040 <free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc20(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    13f3 <rm_link_files+0x213>
jmp    1401 <rm_link_files+0x221>
jmp    1227 <rm_link_files+0x47>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_link_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x8(%rsp)
test   %rsi,%rsi
je     13a2 <rm_link_files+0x1c2>
mov    %rsi,%rdi
call   10f0 <strdup@plt>
lea    0xdf5(%rip),%rsi
mov    %rax,(%rsp)
mov    %rax,%rdi
jmp    1249 <rm_link_files+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %edi,%edi
lea    0xdb7(%rip),%rsi
call   10e0 <strtok@plt>
test   %rax,%rax
je     1399 <rm_link_files+0x1b9>
mov    %rax,%rdi
call   1050 <resolve_ambig@plt>
test   %rax,%rax
je     13a2 <rm_link_files+0x1c2>
mov    %rax,%r13
lea    0xd90(%rip),%rdi
mov    %rdi,%r15
lea    0xd98(%rip),%rbx
mov    %rbx,%rsi
mov    %rax,%rdx
call   1060 <cond@plt>
mov    %rax,%rbp
lea    0xd85(%rip),%rdi
mov    %rbx,%rsi
mov    0x8(%rsp),%rdx
call   1060 <cond@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   10d0 <_and_@plt>
mov    %rax,%rdi
call   1080 <where@plt>
lea    0xd63(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
call   1090 <construct_delete@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10b0 <exec_nonquery@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
lea    0xd47(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
mov    %r15,%rbp
mov    %r15,%rdi
call   1030 <count@plt>
mov    %rax,%r15
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %r12,%rdi
call   10a0 <from@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
lea    0xcf5(%rip),%rsi
mov    %r13,%rdx
call   1060 <cond@plt>
mov    %rax,%rdi
call   1080 <where@plt>
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1100 <construct_query@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   10c0 <exec_int_scalarquery@plt>
test   %eax,%eax
jne    1220 <rm_link_files+0x40>
lea    0xcf4(%rip),%rdi
lea    0xcb1(%rip),%rsi
mov    %r13,%rdx
call   1060 <cond@plt>
mov    %rax,%rdi
call   1080 <where@plt>
lea    0xccb(%rip),%rdi
mov    %eax,%esi
call   1090 <construct_delete@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <exec_nonquery@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
jmp    1220 <rm_link_files+0x40>
mov    (%rsp),%rdi
call   1040 <free@plt>
add    $0x28,%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 = [2 x i8] c"=\00"
@.str.3 = [8 x i8] c"ID_ASOC\00"
@.str.4 = [16 x i8] c"GP_ASOCIACIONES\00"
@.str.5 = [23 x i8] c"- Deasociated file %s\0A\00"
@.str.6 = [11 x i8] c"GP_ARCHIVO\00"
@.str.7 = [13 x i8] c"RUTA_ARCHIVO\00"
define void @rm_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 i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [2 x i8*]
%14 = alloca i32
%15 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %87
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = call i8* @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %6
store i8* null, i8** %7
br label %23
23: ; preds = %83, %18
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %84
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i8* @resolve_ambig(i8* %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %82
31: ; preds = %26
store i8* null, i8** %7
%32 = load i8*, i8** %8
%33 = call i8* @cond(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %3
%35 = call i8* @cond(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i8* %35, i8** %10
%36 = load i8*, i8** %9
%37 = load i8*, i8** %10
%38 = call i8* @_and_(i8* %36, i8* %37)
%39 = call i32 @where(i8* %38)
%40 = call i8* @construct_delete(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %39)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = call i32 @exec_nonquery(i8* %41)
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %9
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %8
%48 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %47)
store i8* null, i8** %11
%49 = call i8* @count(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %49, i8** %12
%50 = getelementptr inbounds [2 x i8*], [2 x i8*]* %13, i64 0, i64 0
%51 = load i8*, i8** %12
store i8* %51, i8** %50
%52 = getelementptr inbounds i8*, i8** %50, i64 1
store i8* null, i8** %52
%53 = getelementptr inbounds [2 x i8*], [2 x i8*]* %13, i64 0, i64 0
%54 = call i32 @from(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%55 = load i8*, i8** %8
%56 = call i8* @cond(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i32 @where(i8* %56)
%58 = call i8* @construct_query(i8** %53, i32 %54, i32 %57, i32 0, i32 0)
store i8* %58, i8** %11
%59 = load i8*, i8** %11
%60 = call i32 @exec_int_scalarquery(i8* %59)
store i32 %60, i32* %14
%61 = load i32, i32* %14
%62 = icmp ne i32 %61, 0
br i1 %62, label %72, label %63
63: ; preds = %31
store i8* null, i8** %15
%64 = load i8*, i8** %8
%65 = call i8* @cond(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = call i32 @where(i8* %65)
%67 = call i8* @construct_delete(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %66)
store i8* %67, i8** %15
%68 = load i8*, i8** %15
%69 = call i32 @exec_nonquery(i8* %68)
%70 = load i8*, i8** %15
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %63, %31
%73 = load i8*, i8** %12
%74 = call i32 @free(i8* %73)
%75 = load i8*, i8** %8
%76 = call i32 @free(i8* %75)
%77 = load i8*, i8** %11
%78 = call i32 @free(i8* %77)
%79 = load i8*, i8** %7
%80 = call i32 @free(i8* %79)
%81 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %81, i8** %6
br label %83
82: ; preds = %26
br label %87
83: ; preds = %72
br label %23
84: ; preds = %23
%85 = load i8*, i8** %5
%86 = call i32 @free(i8* %85)
br label %87
87: ; preds = %82, %84, %2
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [18 x i8] c"RUTA_ARCHIVO_ASOC\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [8 x i8] c"ID_ASOC\00"
@.str.4 = [16 x i8] c"GP_ASOCIACIONES\00"
@.str.5 = [23 x i8] c"- Deasociated file %s\0A\00"
@.str.6 = [11 x i8] c"GP_ARCHIVO\00"
@.str.7 = [13 x i8] c"RUTA_ARCHIVO\00"
define void @rm_link_files(i8* %0, i8* %1) {
%3 = alloca [2 x i8*]
%4 = icmp eq i8* %1, null
br i1 %4, label %49, label %5
5: ; preds = %2
%6 = tail call i8* @strdup(i8* %1)
%7 = tail call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %47, label %9
9: ; preds = %5
%10 = bitcast [2 x i8*]* %3 to i8*
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
br label %13
13: ; preds = %9, %40
%14 = phi i8* [ %7, %9 ], [ %45, %40 ]
%15 = call i8* @resolve_ambig(i8* %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %49, label %17
17: ; preds = %13
%18 = call i8* @cond(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%19 = call i8* @cond(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = call i8* @_and_(i8* %18, i8* %19)
%21 = call i32 @where(i8* %20)
%22 = call i8* @construct_delete(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = call i32 @exec_nonquery(i8* %22)
%24 = call i32 @free(i8* %19)
%25 = call i32 @free(i8* %18)
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%27 = call i8* @count(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %11
store i8* null, i8** %12
%28 = call i32 @from(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%29 = call i8* @cond(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%30 = call i32 @where(i8* %29)
%31 = call i8* @construct_query(i8** %11, i32 %28, i32 %30, i32 0, i32 0)
%32 = call i32 @exec_int_scalarquery(i8* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %17
%35 = call i8* @cond(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%36 = call i32 @where(i8* %35)
%37 = call i8* @construct_delete(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = call i32 @exec_nonquery(i8* %37)
%39 = call i32 @free(i8* %37)
br label %40
40: ; preds = %17, %34
%41 = call i32 @free(i8* %27)
%42 = call i32 @free(i8* %15)
%43 = call i32 @free(i8* %31)
%44 = call i32 @free(i8* %22)
%45 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %13
47: ; preds = %40, %5
%48 = call i32 @free(i8* %6)
br label %49
49: ; preds = %13, %47, %2
ret void
}