#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 void FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(void *);
void *fopen(char *, char *);
int getline(char **, size_t *, void *);
char **malloc(int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
char **getsites(char *filename) {
  FILE *fp;
  char *line = (void *)0;
  size_t len = 0;
  ssize_t read;
  char **result;
  int i = 0;
  result = malloc(30 * sizeof(char *));
  memset(result, 0, 30 * sizeof(char *));
  fp = fopen(filename, "r");
  if (fp == (void *)0) {
    printf("Can`t open list of sites for monitoring\n");
    exit(1);
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    line[strlen(line) - 1] = '\0';
    result[i++] = line;
    line = (void *)0;
  }
  result[i] = "other";
  result[i + 1] = (void *)0;
  fclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<getsites>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    $0xf0,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xf0,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f6 <getsites+0x76>
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11fb <getsites+0x7b>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1260 <getsites+0xe0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
movq   $0x0,-0x18(%rbp)
jmp    11fb <getsites+0x7b>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
lea    0xdba(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsites>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0xf0,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xf0,%edx
call   1060 <memset@plt>
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     126d <getsites+0xed>
mov    %rax,%r13
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     123d <getsites+0xbd>
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nop
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x8(%rsp),%rax
mov    %rax,(%r14,%rbp,8)
add    $0x1,%rbp
movq   $0x0,0x8(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    1200 <getsites+0x80>
mov    %ebp,%eax
lea    0xdba(%rip),%rcx
mov    %rcx,(%r14,%rax,8)
movq   $0x0,0x8(%r14,%rax,8)
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd92(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [41 x i8] c"Can`t open list of sites for monitoring\0A\00"
@.str.2 = [6 x i8] c"other\00"
define i8** @getsites(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %4
store i64 0, i64* %5
store i32 0, i32* %8
%9 = call i8** @malloc(i32 240)
store i8** %9, i8*** %7
%10 = load i8**, i8*** %7
%11 = call i32 @memset(i8** %10, i32 0, i32 240)
%12 = load i8*, i8** %2
%13 = call i8* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
br label %20
20: ; preds = %24, %19
%21 = load i8*, i8** %3
%22 = call i32 @getline(i8** %4, i64* %5, i8* %21)
store i32 %22, i32* %6
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %4
%32 = load i8**, i8*** %7
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8*, i8** %32, i64 %35
store i8* %31, i8** %36
store i8* null, i8** %4
br label %20
37: ; preds = %20
%38 = load i8**, i8*** %7
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %41
%42 = load i8**, i8*** %7
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
store i8* null, i8** %46
%47 = load i8*, i8** %3
%48 = call i32 @fclose(i8* %47)
%49 = load i8**, i8*** %7
ret i8** %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"other\00"
@str = [40 x i8] c"Can`t open list of sites for monitoring\00"
define i8** @getsites(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i8** @malloc(i32 240)
%7 = tail call i32 @memset(i8** %6, i32 0, i32 240)
%8 = tail call i8* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call i32 @getline(i8** %2, i64* %3, i8* %8)
%12 = icmp eq i32 %11, -1
br i1 %12, label %30, label %16
13: ; preds = %1
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10, %16
%17 = phi i64 [ %24, %16 ], [ 0, %10 ]
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %2
%24 = add nuw i64 %17, 1
%25 = getelementptr inbounds i8*, i8** %6, i64 %17
store i8* %23, i8** %25
store i8* null, i8** %2
%26 = call i32 @getline(i8** %2, i64* %3, i8* %8)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %16
28: ; preds = %16
%29 = trunc i64 %24 to i32
br label %30
30: ; preds = %28, %10
%31 = phi i32 [ 0, %10 ], [ %29, %28 ]
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %6, i64 %32
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %33
%34 = add nuw nsw i32 %31, 1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %6, i64 %35
store i8* null, i8** %36
%37 = call i32 @fclose(i8* %8)
ret i8** %6
}