#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ addDeviceToAnalyse(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char const *);
int strlen(char *);
size_t loadSpecifiedFiles(const char *fn) {
  size_t add = 0;
  FILE *fp = fopen(fn, "rt");
  if (!fp) {
    perror(fn);
    return add;
  }
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  while ((read = getline(&line, &len, fp)) != -1) {
    line[strlen(line) - 1] = 0;
    addDeviceToAnalyse(line);
    add++;
  }
  free(line);
  fclose(fp);
  return add;
}


x86 assembly (clang, -O0):
<loadSpecifiedFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <loadSpecifiedFiles+0x49>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <loadSpecifiedFiles+0xcb>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1221 <loadSpecifiedFiles+0xb1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1040 <addDeviceToAnalyse@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c9 <loadSpecifiedFiles+0x59>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadSpecifiedFiles>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1225 <loadSpecifiedFiles+0xb5>
mov    %rax,%r14
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
xor    %r13d,%r13d
cmp    $0xffffffff,%eax
je     1203 <loadSpecifiedFiles+0x93>
mov    %rsp,%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax)
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    (%rsp),%rdi
call   1040 <addDeviceToAnalyse@plt>
add    $0x1,%r13
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    11d0 <loadSpecifiedFiles+0x60>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1080 <perror@plt>
xor    %r13d,%r13d
jmp    1214 <loadSpecifiedFiles+0xa4>

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
define i64 @loadSpecifiedFiles(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
store i64 0, i64* %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @perror(i8* %14)
%16 = load i64, i64* %4
store i64 %16, i64* %2
br label %39
17: ; preds = %1
store i8* null, i8** %6
store i64 0, i64* %7
br label %18
18: ; preds = %22, %17
%19 = load i32*, i32** %5
%20 = call i32 @getline(i8** %6, i64* %7, i32* %19)
store i32 %20, i32* %8
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %6
%30 = call i32 @addDeviceToAnalyse(i8* %29)
%31 = load i64, i64* %4
%32 = add i64 %31, 1
store i64 %32, i64* %4
br label %18
33: ; preds = %18
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
%36 = load i32*, i32** %5
%37 = call i32 @fclose(i32* %36)
%38 = load i64, i64* %4
store i64 %38, i64* %2
br label %39
39: ; preds = %33, %13
%40 = load i64, i64* %2
ret i64 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
define i64 @loadSpecifiedFiles(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* %0)
br label %30
8: ; preds = %1
%9 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%10 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%11 = call i32 @getline(i8** %2, i64* %3, i32* %4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %25, label %13
13: ; preds = %8, %13
%14 = phi i64 [ %22, %13 ], [ 0, %8 ]
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %2
%21 = call i32 @addDeviceToAnalyse(i8* %20)
%22 = add i64 %14, 1
%23 = call i32 @getline(i8** %2, i64* %3, i32* %4)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %13
25: ; preds = %13, %8
%26 = phi i64 [ 0, %8 ], [ %22, %13 ]
%27 = load i8*, i8** %2
%28 = call i32 @free(i8* %27)
%29 = call i32 @fclose(i32* %4)
br label %30
30: ; preds = %25, %6
%31 = phi i64 [ %26, %25 ], [ 0, %6 ]
ret i64 %31
}