#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ errno;
int fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int /*<<< orphan*/);
scalar_t__ realloc(char *, int);
char *build_query_from_files(int optind, const int argc, char **argv) {
  struct stat buff;
  int fd;
  int nb_read;
  int new_siz, prev_siz = 0;
  char *my_list = NULL;
  while (optind < argc) {
    fd = open(argv[optind], O_RDONLY);
    if (fd == -1) {
      err(errno, "cannot open file: %s.", argv[optind]);
    }
    if (fstat(fd, &buff) == -1) {
      err(errno, "cannot get file size: %s.", argv[optind]);
    }
    new_siz = prev_siz + buff.st_size;
    new_siz += 2;
    if ((my_list = (char *)realloc(my_list, new_siz * sizeof(char))) == NULL)
      err(errno, "cannot allocate memory to store requested ACs.");
    if ((nb_read = read(fd, &my_list[prev_siz], buff.st_size)) == -1) {
      err(errno, "cannot read file: %s.", argv[optind]);
    }
    close(fd);
    if (my_list[prev_siz + nb_read - 1] != '\n') {
      my_list[prev_siz + nb_read] = '\n';
      my_list[prev_siz + nb_read + 1] = 0;
      prev_siz = new_siz - 1;
    } else {
      prev_siz = new_siz - 2;
    }
    optind++;
  }
  return my_list;
}


x86 assembly (clang, -O0):
<build_query_from_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    130d <build_query_from_files+0x1ad>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d7 <build_query_from_files+0x77>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    120f <build_query_from_files+0xaf>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x28(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1259 <build_query_from_files+0xf9>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    129e <build_query_from_files+0x13e>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     12f6 <build_query_from_files+0x196>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12ff <build_query_from_files+0x19f>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <build_query_from_files+0x21>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_query_from_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
cmp    %esi,%edi
jge    12b6 <build_query_from_files+0x156>
movslq %edi,%rax
lea    (%rdx,%rax,8),%rax
mov    %rax,(%rsp)
sub    %edi,%esi
xor    %r14d,%r14d
xor    %ebx,%ebx
xor    %r12d,%r12d
mov    %rsi,0x10(%rsp)
jmp    11b5 <build_query_from_files+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%rsi
add    $0x1,%r14
mov    %ebp,%r12d
cmp    %r14d,%esi
je     12b6 <build_query_from_files+0x156>
mov    (%rsp),%rax
mov    (%rax,%r14,8),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    11f2 <build_query_from_files+0x92>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rax
mov    (%rax,%r14,8),%rdx
lea    0xe15(%rip),%rsi
xor    %eax,%eax
call   1050 <err@plt>
mov    %r13d,%edi
lea    0x8(%rsp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1223 <build_query_from_files+0xc3>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rax
mov    (%rax,%r14,8),%rdx
lea    0xdfa(%rip),%rsi
xor    %eax,%eax
call   1050 <err@plt>
mov    0x8(%rsp),%ebp
lea    (%r12,%rbp,1),%esi
add    $0x2,%esi
mov    %rbx,%rdi
call   1060 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1255 <build_query_from_files+0xf5>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1050 <err@plt>
movslq %r12d,%rsi
add    %rbx,%rsi
mov    %r13d,%edi
mov    %ebp,%edx
call   1040 <read@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    128c <build_query_from_files+0x12c>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rax
mov    (%rax,%r14,8),%rdx
lea    0xdda(%rip),%rsi
xor    %eax,%eax
call   1050 <err@plt>
add    %r12d,%ebp
mov    %r13d,%edi
call   1030 <close@plt>
add    %r12d,%r15d
movslq %r15d,%rax
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11a0 <build_query_from_files+0x40>
movw   $0xa,(%rbx,%rax,1)
add    $0x1,%ebp
jmp    11a0 <build_query_from_files+0x40>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@errno = global i32 0
@.str = [22 x i8] c"cannot open file: %s.\00"
@.str.1 = [26 x i8] c"cannot get file size: %s.\00"
@.str.2 = [47 x i8] c"cannot allocate memory to store requested ACs.\00"
@.str.3 = [22 x i8] c"cannot read file: %s.\00"
define i8* @build_query_from_files(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i32 0, i32* %11
store i8* null, i8** %12
br label %13
13: ; preds = %115, %3
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %118
17: ; preds = %13
%18 = load i8**, i8*** %6
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %35
27: ; preds = %17
%28 = load i32, i32* @errno
%29 = load i8**, i8*** %6
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @err(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %27, %17
%36 = load i32, i32* %8
%37 = call i32 @fstat(i32 %36, %struct.stat* %7)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = load i32, i32* @errno
%41 = load i8**, i8*** %6
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 (i32, i8*, ...) @err(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %39, %35
%48 = load i32, i32* %11
%49 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%50 = load i32, i32* %49
%51 = add nsw i32 %48, %50
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 2
store i32 %53, i32* %10
%54 = load i8*, i8** %12
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = mul i64 %56, 1
%58 = trunc i64 %57 to i32
%59 = call i64 @realloc(i8* %54, i32 %58)
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %12
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %47
%63 = load i32, i32* @errno
%64 = call i32 (i32, i8*, ...) @err(i32 %63, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %65
65: ; preds = %62, %47
%66 = load i32, i32* %8
%67 = load i8*, i8** %12
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @read(i32 %66, i8* %70, i32 %72)
store i32 %73, i32* %9
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %83
75: ; preds = %65
%76 = load i32, i32* @errno
%77 = load i8**, i8*** %6
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = call i32 (i32, i8*, ...) @err(i32 %76, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %75, %65
%84 = load i32, i32* %8
%85 = call i32 @close(i32 %84)
%86 = load i8*, i8** %12
%87 = load i32, i32* %11
%88 = load i32, i32* %9
%89 = add nsw i32 %87, %88
%90 = sub nsw i32 %89, 1
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %86, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp ne i32 %94, 10
br i1 %95, label %96, label %112
96: ; preds = %83
%97 = load i8*, i8** %12
%98 = load i32, i32* %11
%99 = load i32, i32* %9
%100 = add nsw i32 %98, %99
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %97, i64 %101
store i8 10, i8* %102
%103 = load i8*, i8** %12
%104 = load i32, i32* %11
%105 = load i32, i32* %9
%106 = add nsw i32 %104, %105
%107 = add nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %103, i64 %108
store i8 0, i8* %109
%110 = load i32, i32* %10
%111 = sub nsw i32 %110, 1
store i32 %111, i32* %11
br label %115
112: ; preds = %83
%113 = load i32, i32* %10
%114 = sub nsw i32 %113, 2
store i32 %114, i32* %11
br label %115
115: ; preds = %112, %96
%116 = load i32, i32* %4
%117 = add nsw i32 %116, 1
store i32 %117, i32* %4
br label %13
118: ; preds = %13
%119 = load i8*, i8** %12
ret i8* %119
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@errno = global i32 0
@.str = [22 x i8] c"cannot open file: %s.\00"
@.str.1 = [26 x i8] c"cannot get file size: %s.\00"
@.str.2 = [47 x i8] c"cannot allocate memory to store requested ACs.\00"
@.str.3 = [22 x i8] c"cannot read file: %s.\00"
define i8* @build_query_from_files(i32 %0, i32 %1, i8** nocapture %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = icmp slt i32 %0, %1
br i1 %6, label %7, label %71
7: ; preds = %3
%8 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%9 = sext i32 %0 to i64
br label %10
10: ; preds = %7, %64
%11 = phi i64 [ %9, %7 ], [ %66, %64 ]
%12 = phi i8* [ null, %7 ], [ %35, %64 ]
%13 = phi i32 [ 0, %7 ], [ %65, %64 ]
%14 = getelementptr inbounds i8*, i8** %2, i64 %11
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* @errno
%21 = load i8*, i8** %14
%22 = tail call i32 (i32, i8*, ...) @err(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %10
%24 = call i32 @fstat(i32 %17, %struct.stat* %4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = load i8*, i8** %14
%29 = tail call i32 (i32, i8*, ...) @err(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %23
%31 = load i32, i32* %8
%32 = add nsw i32 %31, %13
%33 = add nsw i32 %32, 2
%34 = tail call i64 @realloc(i8* %12, i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = icmp eq i64 %34, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i32, i32* @errno
%39 = tail call i32 (i32, i8*, ...) @err(i32 %38, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %37, %30
%41 = sext i32 %13 to i64
%42 = getelementptr inbounds i8, i8* %35, i64 %41
%43 = tail call i32 @read(i32 %17, i8* %42, i32 %31)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i32, i32* @errno
%47 = load i8*, i8** %14
%48 = tail call i32 (i32, i8*, ...) @err(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45, %40
%50 = tail call i32 @close(i32 %17)
%51 = add nsw i32 %43, %13
%52 = add nsw i32 %51, -1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %35, i64 %53
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 10
br i1 %56, label %64, label %57
57: ; preds = %49
%58 = sext i32 %51 to i64
%59 = getelementptr inbounds i8, i8* %35, i64 %58
store i8 10, i8* %59
%60 = add nsw i32 %51, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %35, i64 %61
store i8 0, i8* %62
%63 = add nsw i32 %32, 1
br label %64
64: ; preds = %49, %57
%65 = phi i32 [ %63, %57 ], [ %32, %49 ]
%66 = add nsw i64 %11, 1
%67 = trunc i64 %66 to i32
%68 = icmp eq i32 %67, %1
br i1 %68, label %69, label %10
69: ; preds = %64
%70 = inttoptr i64 %34 to i8*
br label %71
71: ; preds = %69, %3
%72 = phi i8* [ null, %3 ], [ %70, %69 ]
ret i8* %72
}