#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
char *malloc(int);
char *smprintf(char *, ...);
char *getwifi() {
  char *status = malloc(sizeof(char) * 12);
  FILE *fp = NULL;
  if ((fp = fopen("/sys/class/net/wlp1s0/operstate", "r"))) {
    fscanf(fp, "%s", status);
    fclose(fp);
    return smprintf("%s", status);
  } else
    return smprintf("");
}


x86 assembly (clang, -O0):
<getwifi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe8b(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c7 <getwifi+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <smprintf@plt>
mov    %rax,-0x8(%rbp)
jmp    11d9 <getwifi+0x89>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <smprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getwifi>:
push   %r15
push   %r14
push   %rbx
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe97(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ac <getwifi+0x5c>
mov    %rax,%rbx
lea    0xe9e(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <smprintf@plt>
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <smprintf@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"/sys/class/net/wlp1s0/operstate\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @getwifi() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32*
%4 = call i8* @malloc(i32 12)
store i8* %4, i8** %2
store i32* null, i32** %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = load i32*, i32** %3
%9 = load i8*, i8** %2
%10 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i32*, i32** %3
%12 = call i32 @fclose(i32* %11)
%13 = load i8*, i8** %2
%14 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
store i8* %14, i8** %1
br label %17
15: ; preds = %0
%16 = call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i8* %16, i8** %1
br label %17
17: ; preds = %15, %7
%18 = load i8*, i8** %1
ret i8* %18
}

LLVM IR (-O2):
@.str = [32 x i8] c"/sys/class/net/wlp1s0/operstate\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @getwifi() {
%1 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%6 = tail call i32 @fclose(i32* %2)
%7 = tail call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %10
8: ; preds = %0
%9 = tail call i8* (i8*, ...) @smprintf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = phi i8* [ %7, %4 ], [ %9, %8 ]
ret i8* %11
}