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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ *malloc(int);
int ptg_file_lines(char const *);
int /*<<< orphan*/ ptg_parse_ip_line(char *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
void ptg_read_ip_file(const char *filename, int *lncnt, uint32_t **startips,
                      uint32_t **endips) {
  FILE *fp;
  char lnbuf[128];
  int i = 0;
  *lncnt = ptg_file_lines(filename);
  if (*lncnt <= 0) {
    *startips = *endips = NULL;
    return;
  }
  *startips = malloc(2 * (*lncnt) * sizeof(uint32_t));
  *endips = (*startips) + (*lncnt);
  fp = fopen(filename, "r");
  if (fp == NULL) {
    *lncnt = 0;
    *startips = *endips = NULL;
    return;
  }
  while (fgets(lnbuf, 127, fp) != NULL) {
    ptg_parse_ip_line(lnbuf, &(*startips)[i], &(*endips)[i]);
    i++;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<ptg_read_ip_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0xb4(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ptg_file_lines@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11be <ptg_read_ip_file+0x5e>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
jmp    12b5 <ptg_read_ip_file+0x155>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123e <ptg_read_ip_file+0xde>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
jmp    12b5 <ptg_read_ip_file+0x155>
jmp    1243 <ptg_read_ip_file+0xe3>
lea    -0xb0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x7f,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12ac <ptg_read_ip_file+0x14c>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
movslq -0xb4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
movslq -0xb4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
call   1070 <ptg_parse_ip_line@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1243 <ptg_read_ip_file+0xe3>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptg_read_ip_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
call   1030 <ptg_file_lines@plt>
mov    %eax,(%r12)
test   %eax,%eax
jle    121f <ptg_read_ip_file+0xbf>
mov    %eax,%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %ebx,%ecx
lea    (%rax,%rcx,4),%rax
mov    %rax,(%r15)
lea    0xe52(%rip),%rsi
mov    %r13,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1217 <ptg_read_ip_file+0xb7>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x7f,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     120d <ptg_read_ip_file+0xad>
xor    %ebx,%ebx
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rsi
add    %rbx,%rsi
mov    (%r15),%rdx
add    %rbx,%rdx
mov    %r12,%rdi
call   1070 <ptg_parse_ip_line@plt>
mov    %r12,%rdi
mov    $0x7f,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
add    $0x4,%rbx
test   %rax,%rax
jne    11e0 <ptg_read_ip_file+0x80>
mov    %r13,%rdi
call   1040 <fclose@plt>
jmp    122d <ptg_read_ip_file+0xcd>
movl   $0x0,(%r12)
movq   $0x0,(%r15)
movq   $0x0,(%r14)
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @ptg_read_ip_file(i8* %0, i32* %1, i32** %2, i32** %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32**
%8 = alloca i32**
%9 = alloca i32*
%10 = alloca [128 x i8]
%11 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32** %2, i32*** %7
store i32** %3, i32*** %8
store i32 0, i32* %11
%12 = load i8*, i8** %5
%13 = call i32 @ptg_file_lines(i8* %12)
%14 = load i32*, i32** %6
store i32 %13, i32* %14
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32**, i32*** %8
store i32* null, i32** %19
%20 = load i32**, i32*** %7
store i32* null, i32** %20
br label %69
21: ; preds = %4
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = mul nsw i32 2, %23
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i32* @malloc(i32 %27)
%29 = load i32**, i32*** %7
store i32* %28, i32** %29
%30 = load i32**, i32*** %7
%31 = load i32*, i32** %30
%32 = load i32*, i32** %6
%33 = load i32, i32* %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %31, i64 %34
%36 = load i32**, i32*** %8
store i32* %35, i32** %36
%37 = load i8*, i8** %5
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %38, i32** %9
%39 = load i32*, i32** %9
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %45
41: ; preds = %21
%42 = load i32*, i32** %6
store i32 0, i32* %42
%43 = load i32**, i32*** %8
store i32* null, i32** %43
%44 = load i32**, i32*** %7
store i32* null, i32** %44
br label %69
45: ; preds = %21
br label %46
46: ; preds = %51, %45
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%48 = load i32*, i32** %9
%49 = call i32* @fgets(i8* %47, i32 127, i32* %48)
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %66
51: ; preds = %46
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%53 = load i32**, i32*** %7
%54 = load i32*, i32** %53
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = load i32**, i32*** %8
%59 = load i32*, i32** %58
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = call i32 @ptg_parse_ip_line(i8* %52, i32* %57, i32* %62)
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
br label %46
66: ; preds = %46
%67 = load i32*, i32** %9
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %66, %41, %18
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @ptg_read_ip_file(i8* %0, i32* nocapture %1, i32** nocapture %2, i32** nocapture %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @ptg_file_lines(i8* %0)
store i32 %7, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %4
store i32* null, i32** %3
store i32* null, i32** %2
br label %33
10: ; preds = %4
%11 = shl i32 %7, 3
%12 = tail call i32* @malloc(i32 %11)
store i32* %12, i32** %2
%13 = zext i32 %7 to i64
%14 = getelementptr inbounds i32, i32* %12, i64 %13
store i32* %14, i32** %3
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = call i32* @fgets(i8* %6, i32 127, i32* %15)
%19 = icmp eq i32* %18, null
br i1 %19, label %31, label %21
20: ; preds = %10
store i32 0, i32* %1
store i32* null, i32** %3
store i32* null, i32** %2
br label %33
21: ; preds = %17, %21
%22 = phi i64 [ %28, %21 ], [ 0, %17 ]
%23 = load i32*, i32** %2
%24 = getelementptr inbounds i32, i32* %23, i64 %22
%25 = load i32*, i32** %3
%26 = getelementptr inbounds i32, i32* %25, i64 %22
%27 = call i32 @ptg_parse_ip_line(i8* %6, i32* %24, i32* %26)
%28 = add nuw i64 %22, 1
%29 = call i32* @fgets(i8* %6, i32 127, i32* %15)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %21
31: ; preds = %21, %17
%32 = call i32 @fclose(i32* %15)
br label %33
33: ; preds = %31, %20, %9
ret void
}