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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ rtl_tracedbg(int /*<<< orphan*/, char *, int, char *,
                                char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ *strstr(char *, char *);
char *AwGetPanPref(char *addr) {
  char sfile[512];
  char buf[512];
  FILE *f;
  char *pt;
  pt = getenv("AW_DATA_DIR");
  if (!pt || !*pt) {
    return NULL;
  }
  addr[0] = '\0';
  sprintf(sfile, "%s/prefipv6.txt", pt);
  f = fopen(sfile, "r");
  if (!f) {
    {
      extern int TraceDebug;
      extern int TraceLevel;
      if (TraceLevel >= (0)) {
        rtl_tracedbg(
            (0),
            TraceDebug <= 0
                ? NULL
                : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/actility/ong/refs/heads/"
                  "master/drivers/watteco/lib/panaddr.c",
            204, "ERROR cannot open file '%s'\n", sfile);
      }
    };
    return NULL;
  }
  while (fgets(buf, sizeof(buf) - 1, f)) {
    pt = strchr(buf, '\n');
    if (pt)
      *pt = '\0';
    pt = strchr(buf, '\r');
    if (pt)
      *pt = '\0';
    if (strstr(buf, "::") == NULL)
      sprintf(addr, "%s::1", buf);
    else
      sprintf(addr, "%s:1", buf);
    break;
  }
  fclose(f);
  return addr;
}


x86 assembly (clang, -O0):
<AwGetPanPref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe6a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     11c0 <AwGetPanPref+0x40>
mov    -0x420(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11cd <AwGetPanPref+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    1356 <AwGetPanPref+0x1d6>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1266 <AwGetPanPref+0xe6>
mov    0x2dbb(%rip),%rax
cmpl   $0x0,(%rax)
jl     1259 <AwGetPanPref+0xd9>
mov    0x2dbb(%rip),%rax
mov    (%rax),%ecx
lea    0xde8(%rip),%rsi
xor    %eax,%eax
cmp    $0x0,%ecx
cmovle %rax,%rsi
lea    -0x210(%rbp),%r8
xor    %edi,%edi
mov    $0xcc,%edx
lea    0xe61(%rip),%rcx
call   1070 <rtl_tracedbg@plt>
movq   $0x0,-0x8(%rbp)
jmp    1356 <AwGetPanPref+0x1d6>
jmp    126b <AwGetPanPref+0xeb>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x1ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1342 <AwGetPanPref+0x1c2>
lea    -0x410(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     12bd <AwGetPanPref+0x13d>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     12ed <AwGetPanPref+0x16d>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    1326 <AwGetPanPref+0x1a6>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xdb9(%rip),%rsi
call   1090 <sprintf@plt>
jmp    133d <AwGetPanPref+0x1bd>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xda3(%rip),%rsi
call   1090 <sprintf@plt>
jmp    1342 <AwGetPanPref+0x1c2>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AwGetPanPref>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0xe6a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     129c <AwGetPanPref+0x11c>
cmpb   $0x0,(%rax)
je     129c <AwGetPanPref+0x11c>
movb   $0x0,(%rbx)
lea    0xe55(%rip),%rsi
lea    0x200(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rdx
call   1090 <sprintf@plt>
lea    0xe4b(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     125c <AwGetPanPref+0xdc>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1ff,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1252 <AwGetPanPref+0xd2>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120b <AwGetPanPref+0x8b>
movb   $0x0,(%rax)
mov    %rsp,%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1220 <AwGetPanPref+0xa0>
movb   $0x0,(%rax)
lea    0xeab(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
lea    0xe99(%rip),%rax
lea    0xe98(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    129e <AwGetPanPref+0x11e>
mov    0x2d75(%rip),%rax
cmpl   $0x0,(%rax)
js     129c <AwGetPanPref+0x11c>
mov    0x2d79(%rip),%rax
xor    %ebx,%ebx
cmpl   $0x0,(%rax)
lea    0xda3(%rip),%rsi
cmovle %rbx,%rsi
lea    0xe2f(%rip),%rcx
lea    0x200(%rsp),%r8
xor    %edi,%edi
mov    $0xcc,%edx
call   1070 <rtl_tracedbg@plt>
jmp    129e <AwGetPanPref+0x11e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"AW_DATA_DIR\00"
@.str.1 = [16 x i8] c"%s/prefipv6.txt\00"
@.str.2 = [2 x i8] c"r\00"
@TraceLevel = external global i32
@TraceDebug = external global i32
@.str.3 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/actility/ong/refs/heads/master/drivers/watteco/lib/panaddr.c\00"
@.str.4 = [29 x i8] c"ERROR cannot open file '%s'\0A\00"
@.str.5 = [3 x i8] c"::\00"
@.str.6 = [6 x i8] c"%s::1\00"
@.str.7 = [5 x i8] c"%s:1\00"
define i8* @AwGetPanPref(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i8*, i8** %7
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11, %1
store i8* null, i8** %2
br label %74
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 0, i8* %18
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%20 = load i8*, i8** %7
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %37, label %26
26: ; preds = %16
%27 = load i32, i32* @TraceLevel
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* @TraceDebug
%31 = icmp sle i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* null, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0)
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%35 = call i32 @rtl_tracedbg(i32 0, i8* %33, i32 204, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %29, %26
store i8* null, i8** %2
br label %74
37: ; preds = %16
br label %38
38: ; preds = %37
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%40 = load i32*, i32** %6
%41 = call i64 @fgets(i8* %39, i32 511, i32* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %70
43: ; preds = %38
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%45 = call i8* @strchr(i8* %44, i8 signext 10)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %7
store i8 0, i8* %49
br label %50
50: ; preds = %48, %43
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%52 = call i8* @strchr(i8* %51, i8 signext 13)
store i8* %52, i8** %7
%53 = load i8*, i8** %7
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = load i8*, i8** %7
store i8 0, i8* %56
br label %57
57: ; preds = %55, %50
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%59 = call i32* @strstr(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i8*, i8** %3
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%64 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %63)
br label %69
65: ; preds = %57
%66 = load i8*, i8** %3
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%68 = call i32 @sprintf(i8* %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %65, %61
br label %70
70: ; preds = %69, %38
%71 = load i32*, i32** %6
%72 = call i32 @fclose(i32* %71)
%73 = load i8*, i8** %3
store i8* %73, i8** %2
br label %74
74: ; preds = %70, %36, %15
%75 = load i8*, i8** %2
ret i8* %75
}

LLVM IR (-O2):
@.str = [12 x i8] c"AW_DATA_DIR\00"
@.str.1 = [16 x i8] c"%s/prefipv6.txt\00"
@.str.2 = [2 x i8] c"r\00"
@TraceLevel = external global i32
@TraceDebug = external global i32
@.str.3 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/actility/ong/refs/heads/master/drivers/watteco/lib/panaddr.c\00"
@.str.4 = [29 x i8] c"ERROR cannot open file '%s'\0A\00"
@.str.5 = [3 x i8] c"::\00"
@.str.6 = [6 x i8] c"%s::1\00"
@.str.7 = [5 x i8] c"%s:1\00"
define i8* @AwGetPanPref(i8* writeonly %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %41, label %8
8: ; preds = %1
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %41, label %11
11: ; preds = %8
store i8 0, i8* %0
%12 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%13 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i32, i32* @TraceLevel
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i32, i32* @TraceDebug
%20 = icmp slt i32 %19, 1
%21 = select i1 %20, i8* null, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0)
%22 = call i32 @rtl_tracedbg(i32 0, i8* %21, i32 204, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %41
23: ; preds = %11
%24 = call i64 @fgets(i8* %5, i32 511, i32* %13)
%25 = icmp eq i64 %24, 0
br i1 %25, label %39, label %26
26: ; preds = %23
%27 = call i8* @strchr(i8* %5, i8 signext 10)
%28 = icmp eq i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26
store i8 0, i8* %27
br label %30
30: ; preds = %29, %26
%31 = call i8* @strchr(i8* %5, i8 signext 13)
%32 = icmp eq i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %30
store i8 0, i8* %31
br label %34
34: ; preds = %33, %30
%35 = call i32* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i32* %35, null
%37 = select i1 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%38 = call i32 @sprintf(i8* %0, i8* dereferenceable(1) %37, i8* %5)
br label %39
39: ; preds = %34, %23
%40 = call i32 @fclose(i32* %13)
br label %41
41: ; preds = %15, %18, %1, %8, %39
%42 = phi i8* [ %0, %39 ], [ null, %8 ], [ null, %1 ], [ null, %18 ], [ null, %15 ]
ret i8* %42
}