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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
char *realloc(char *, int);
char *skip_space_at_begin(char *);
char *skip_space_at_end(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int get_blackip(char *filename, char **ips) {
  char *buf1;
  char buf2[1024];
  FILE *fp;
  if (filename == NULL) {
    *ips = NULL;
    return -1;
  }
  buf1 = (char *)malloc(65536);
  if (!buf1) {
    fprintf(stderr, "out of memory\n");
    *ips = NULL;
    return -1;
  }
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "open %s failed\n", filename);
    *ips = NULL;
    free(buf1);
    return -1;
  }
  char *p1, *p2;
  int l;
  buf2[0] = '\0';
  buf1[0] = '\0';
  while (fgets(buf2, 1024, fp) != NULL) {
    p1 = buf2;
    p1 = skip_space_at_begin(p1);
    if (*p1 == '#' || *p1 == '\0')
      continue;
    p2 = strchr(p1, '\0');
    p2--;
    p2 = skip_space_at_end(p2);
    l = p2 - p1;
    if (buf1[0] != '\0') {
      strcat(buf1, "|");
    }
    strncat(buf1, p1, l);
  }
  fclose(fp);
  l = strlen(buf1);
  buf1 = realloc(buf1, l + 1);
  *ips = buf1;
  return 0;
}


x86 assembly (clang, -O0):
<get_blackip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1205 <get_blackip+0x35>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <get_blackip+0x227>
mov    $0x10000,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124c <get_blackip+0x7c>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <get_blackip+0x227>
mov    -0x10(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    12ac <get_blackip+0xdc>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <get_blackip+0x227>
movb   $0x0,-0x420(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13b4 <get_blackip+0x1e4>
lea    -0x420(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rdi
call   10d0 <skip_space_at_begin@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1323 <get_blackip+0x153>
mov    -0x430(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1328 <get_blackip+0x158>
jmp    12ba <get_blackip+0xea>
mov    -0x430(%rbp),%rdi
xor    %esi,%esi
call   1060 <strchr@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdi
call   1070 <skip_space_at_end@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
mov    -0x430(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x43c(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1399 <get_blackip+0x1c9>
mov    -0x20(%rbp),%rdi
lea    0xc8d(%rip),%rsi
call   10f0 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x430(%rbp),%rsi
mov    -0x43c(%rbp),%edx
call   1080 <strncat@plt>
jmp    12ba <get_blackip+0xea>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x43c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x43c(%rbp),%esi
add    $0x1,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_blackip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
test   %rdi,%rdi
je     12e4 <get_blackip+0x124>
mov    %rdi,%rbx
mov    $0x10000,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12cd <get_blackip+0x10d>
mov    %rax,%r15
lea    0xe12(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12ed <get_blackip+0x12d>
mov    %rax,%r12
movb   $0x0,(%rsp)
movb   $0x0,(%r15)
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12ab <get_blackip+0xeb>
mov    %rsp,%rbx
jmp    1263 <get_blackip+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1070 <strncat@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12ab <get_blackip+0xeb>
mov    %rbx,%rdi
call   10c0 <skip_space_at_begin@plt>
mov    %rax,%rbp
movzbl (%rax),%eax
cmp    $0x23,%al
je     124e <get_blackip+0x8e>
test   %al,%al
je     124e <get_blackip+0x8e>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rdi
add    $0xffffffffffffffff,%rdi
call   1060 <skip_space_at_end@plt>
mov    %rax,%r13
sub    %ebp,%r13d
cmpb   $0x0,(%r15)
je     1240 <get_blackip+0x80>
mov    %r15,%rdi
lea    0xd7d(%rip),%rsi
call   10e0 <strcat@plt>
jmp    1240 <get_blackip+0x80>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r15,%rdi
call   10b0 <realloc@plt>
mov    %rax,(%r14)
xor    %eax,%eax
jmp    131b <get_blackip+0x15b>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd23(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
movq   $0x0,(%r14)
jmp    1316 <get_blackip+0x156>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
movq   $0x0,(%r14)
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"open %s failed\0A\00"
@.str.3 = [2 x i8] c"|\00"
define i32 @get_blackip(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i8**, i8*** %5
store i8* null, i8** %15
store i32 -1, i32* %3
br label %97
16: ; preds = %2
%17 = call i64 @malloc(i32 65536)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%24 = load i8**, i8*** %5
store i8* null, i8** %24
store i32 -1, i32* %3
br label %97
25: ; preds = %16
%26 = load i8*, i8** %4
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %4
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i8**, i8*** %5
store i8* null, i8** %34
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
store i32 -1, i32* %3
br label %97
37: ; preds = %25
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8 0, i8* %38
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 0
store i8 0, i8* %40
br label %41
41: ; preds = %81, %59, %37
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%43 = load i32*, i32** %8
%44 = call i32* @fgets(i8* %42, i32 1024, i32* %43)
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %86
46: ; preds = %41
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8* %47, i8** %9
%48 = load i8*, i8** %9
%49 = call i8* @skip_space_at_begin(i8* %48)
store i8* %49, i8** %9
%50 = load i8*, i8** %9
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 35
br i1 %53, label %59, label %54
54: ; preds = %46
%55 = load i8*, i8** %9
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54, %46
br label %41
60: ; preds = %54
%61 = load i8*, i8** %9
%62 = call i8* @strchr(i8* %61, i8 signext 0)
store i8* %62, i8** %10
%63 = load i8*, i8** %10
%64 = getelementptr inbounds i8, i8* %63, i32 -1
store i8* %64, i8** %10
%65 = load i8*, i8** %10
%66 = call i8* @skip_space_at_end(i8* %65)
store i8* %66, i8** %10
%67 = load i8*, i8** %10
%68 = load i8*, i8** %9
%69 = ptrtoint i8* %67 to i64
%70 = ptrtoint i8* %68 to i64
%71 = sub i64 %69, %70
%72 = trunc i64 %71 to i32
store i32 %72, i32* %11
%73 = load i8*, i8** %6
%74 = getelementptr inbounds i8, i8* %73, i64 0
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %60
%79 = load i8*, i8** %6
%80 = call i32 @strcat(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %81
81: ; preds = %78, %60
%82 = load i8*, i8** %6
%83 = load i8*, i8** %9
%84 = load i32, i32* %11
%85 = call i32 @strncat(i8* %82, i8* %83, i32 %84)
br label %41
86: ; preds = %41
%87 = load i32*, i32** %8
%88 = call i32 @fclose(i32* %87)
%89 = load i8*, i8** %6
%90 = call i32 @strlen(i8* %89)
store i32 %90, i32* %11
%91 = load i8*, i8** %6
%92 = load i32, i32* %11
%93 = add nsw i32 %92, 1
%94 = call i8* @realloc(i8* %91, i32 %93)
store i8* %94, i8** %6
%95 = load i8*, i8** %6
%96 = load i8**, i8*** %5
store i8* %95, i8** %96
store i32 0, i32* %3
br label %97
97: ; preds = %86, %30, %21, %14
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"open %s failed\0A\00"
@.str.3 = [2 x i8] c"|\00"
define i32 @get_blackip(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %7
6: ; preds = %2
store i8* null, i8** %1
br label %50
7: ; preds = %2
%8 = tail call i64 @malloc(i32 65536)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
br label %50
14: ; preds = %7
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %0)
store i8* null, i8** %1
%20 = tail call i32 @free(i8* %9)
br label %50
21: ; preds = %14
store i8 0, i8* %4
store i8 0, i8* %9
%22 = call i32* @fgets(i8* %4, i32 1024, i32* %15)
%23 = icmp eq i32* %22, null
br i1 %23, label %45, label %24
24: ; preds = %21, %27
%25 = call i8* @skip_space_at_begin(i8* %4)
%26 = load i8, i8* %25
switch i8 %26, label %30 [
i8 35, label %27
i8 0, label %27
]
27: ; preds = %24, %24, %43
%28 = call i32* @fgets(i8* %4, i32 1024, i32* %15)
%29 = icmp eq i32* %28, null
br i1 %29, label %45, label %24
30: ; preds = %24
%31 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %25)
%32 = getelementptr i8, i8* %25, i64 -1
%33 = getelementptr inbounds i8, i8* %32, i64 %31
%34 = call i8* @skip_space_at_end(i8* %33)
%35 = ptrtoint i8* %34 to i64
%36 = ptrtoint i8* %25 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = load i8, i8* %9
%40 = icmp eq i8 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %30
%42 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %30
%44 = call i32 @strncat(i8* %9, i8* %25, i32 %38)
br label %27
45: ; preds = %27, %21
%46 = call i32 @fclose(i32* %15)
%47 = call i32 @strlen(i8* %9)
%48 = add nsw i32 %47, 1
%49 = call i8* @realloc(i8* %9, i32 %48)
store i8* %49, i8** %1
br label %50
50: ; preds = %45, %17, %11, %6
%51 = phi i32 [ -1, %6 ], [ -1, %17 ], [ 0, %45 ], [ -1, %11 ]
ret i32 %51
}