#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*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
char *AwGetRadioMode(char *mode) {
  char sfile[512];
  char buf[512];
  FILE *f;
  char *pt;
  pt = getenv("AW_DATA_DIR");
  if (!pt || !*pt) {
    return NULL;
  }
  mode[0] = '\0';
  sprintf(sfile, "%s/routeraddr.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",
            160, "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 (strncmp(buf, "type=", 5) == 0) {
      pt = buf + 5;
      if (!strcmp(pt, "rf212") || !strcmp(pt, "lora")) {
        strcpy(mode, pt);
        break;
      }
    }
  }
  fclose(f);
  return mode;
}


x86 assembly (clang, -O0):
<AwGetRadioMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe4a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     11e0 <AwGetRadioMode+0x40>
mov    -0x420(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11ed <AwGetRadioMode+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    13ac <AwGetRadioMode+0x20c>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    -0x420(%rbp),%rdx
lea    0xe03(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1286 <AwGetRadioMode+0xe6>
mov    0x2d9b(%rip),%rax
cmpl   $0x0,(%rax)
jl     1279 <AwGetRadioMode+0xd9>
mov    0x2d9b(%rip),%rax
mov    (%rax),%ecx
lea    0xdca(%rip),%rsi
xor    %eax,%eax
cmp    $0x0,%ecx
cmovle %rax,%rsi
lea    -0x210(%rbp),%r8
xor    %edi,%edi
mov    $0xa0,%edx
lea    0xe43(%rip),%rcx
call   10a0 <rtl_tracedbg@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ac <AwGetRadioMode+0x20c>
jmp    128b <AwGetRadioMode+0xeb>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x1ff,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1398 <AwGetRadioMode+0x1f8>
lea    -0x410(%rbp),%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     12dd <AwGetRadioMode+0x13d>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     130d <AwGetRadioMode+0x16d>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1393 <AwGetRadioMode+0x1f3>
lea    -0x410(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
lea    0xd8b(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
je     1379 <AwGetRadioMode+0x1d9>
mov    -0x420(%rbp),%rdi
lea    0xd75(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    138e <AwGetRadioMode+0x1ee>
mov    -0x10(%rbp),%rdi
mov    -0x420(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    1398 <AwGetRadioMode+0x1f8>
jmp    1393 <AwGetRadioMode+0x1f3>
jmp    128b <AwGetRadioMode+0xeb>
mov    -0x418(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AwGetRadioMode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12fe <AwGetRadioMode+0x16e>
cmpb   $0x0,(%rax)
je     12fe <AwGetRadioMode+0x16e>
movb   $0x0,(%r14)
lea    0xe3f(%rip),%rsi
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   10b0 <sprintf@plt>
lea    0xe37(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12bd <AwGetRadioMode+0x12d>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x1ff,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12b3 <AwGetRadioMode+0x123>
mov    %rsp,%rbx
lea    0xeb6(%rip),%r13
mov    $0x31326672,%ebp
mov    $0x61726f6c,%r15d
jmp    1245 <AwGetRadioMode+0xb5>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12b3 <AwGetRadioMode+0x123>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     125a <AwGetRadioMode+0xca>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     126f <AwGetRadioMode+0xdf>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1230 <AwGetRadioMode+0xa0>
mov    0x5(%rsp),%eax
xor    %ebp,%eax
movzwl 0x9(%rsp),%ecx
xor    $0x32,%ecx
or     %eax,%ecx
je     12a6 <AwGetRadioMode+0x116>
mov    0x5(%rsp),%eax
xor    %r15d,%eax
movzbl 0x9(%rsp),%ecx
or     %eax,%ecx
jne    1230 <AwGetRadioMode+0xa0>
mov    %r14,%rdi
lea    0x5(%rsp),%rsi
call   1050 <strcpy@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
jmp    1301 <AwGetRadioMode+0x171>
mov    0x2d14(%rip),%rax
cmpl   $0x0,(%rax)
js     12fe <AwGetRadioMode+0x16e>
mov    0x2d18(%rip),%rax
xor    %r14d,%r14d
cmpl   $0x0,(%rax)
lea    0xd43(%rip),%rsi
cmovle %r14,%rsi
lea    0xdcf(%rip),%rcx
lea    0x200(%rsp),%r8
xor    %edi,%edi
mov    $0xa0,%edx
call   1090 <rtl_tracedbg@plt>
jmp    1301 <AwGetRadioMode+0x171>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"AW_DATA_DIR\00"
@.str.1 = [18 x i8] c"%s/routeraddr.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 = [6 x i8] c"type=\00"
@.str.6 = [6 x i8] c"rf212\00"
@.str.7 = [5 x i8] c"lora\00"
define i8* @AwGetRadioMode(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 %81
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 ([18 x i8], [18 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 160, 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 %81
37: ; preds = %16
br label %38
38: ; preds = %76, %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 %77
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 i64 @strncmp(i8* %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %76
61: ; preds = %57
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%63 = getelementptr inbounds i8, i8* %62, i64 5
store i8* %63, i8** %7
%64 = load i8*, i8** %7
%65 = call i32 @strcmp(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %61
%68 = load i8*, i8** %7
%69 = call i32 @strcmp(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%70 = icmp ne i32 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %67, %61
%72 = load i8*, i8** %3
%73 = load i8*, i8** %7
%74 = call i32 @strcpy(i8* %72, i8* %73)
br label %77
75: ; preds = %67
br label %76
76: ; preds = %75, %57
br label %38
77: ; preds = %71, %38
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
%80 = load i8*, i8** %3
store i8* %80, i8** %2
br label %81
81: ; preds = %77, %36, %15
%82 = load i8*, i8** %2
ret i8* %82
}

LLVM IR (-O2):
@.str = [12 x i8] c"AW_DATA_DIR\00"
@.str.1 = [18 x i8] c"%s/routeraddr.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 = [6 x i8] c"type=\00"
@.str.6 = [6 x i8] c"rf212\00"
@.str.7 = [5 x i8] c"lora\00"
define i8* @AwGetRadioMode(i8* %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 %52, label %8
8: ; preds = %1
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %52, label %11
11: ; preds = %8
store i8 0, i8* %0
%12 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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 %20, label %15
15: ; preds = %11
%16 = call i64 @fgets(i8* %5, i32 511, i32* %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %50, label %18
18: ; preds = %15
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 5
br label %28
20: ; preds = %11
%21 = load i32, i32* @TraceLevel
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %52
23: ; preds = %20
%24 = load i32, i32* @TraceDebug
%25 = icmp slt i32 %24, 1
%26 = select i1 %25, i8* null, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0)
%27 = call i32 @rtl_tracedbg(i32 0, i8* %26, i32 160, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %52
28: ; preds = %18, %47
%29 = call i8* @strchr(i8* %5, i8 signext 10)
%30 = icmp eq i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %28
store i8 0, i8* %29
br label %32
32: ; preds = %31, %28
%33 = call i8* @strchr(i8* %5, i8 signext 13)
%34 = icmp eq i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %32
store i8 0, i8* %33
br label %36
36: ; preds = %35, %32
%37 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = call i32 @bcmp(i8* dereferenceable(6) %19, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 6)
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = call i32 @bcmp(i8* dereferenceable(5) %19, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 5)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42, %39
%46 = call i32 @strcpy(i8* %0, i8* %19)
br label %50
47: ; preds = %42, %36
%48 = call i64 @fgets(i8* %5, i32 511, i32* %13)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %28
50: ; preds = %47, %15, %45
%51 = call i32 @fclose(i32* %13)
br label %52
52: ; preds = %20, %23, %1, %8, %50
%53 = phi i8* [ %0, %50 ], [ null, %8 ], [ null, %1 ], [ null, %23 ], [ null, %20 ]
ret i8* %53
}