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

/* Variables and functions */
int MAX_LINKS;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int get_netlink_num(void) {
  FILE *fp;
  int netlink_num = (MAX_LINKS - 1);
  char str[64];
  char *srch = "netlink_num";
  fp = fopen("/proc/mwlan/config", "r");
  if (fp) {
    while (!feof(fp)) {
      fgets(str, sizeof(str), fp);
      if (strncmp(str, srch, strlen(srch)) == 0) {
        netlink_num = atoi(str + strlen(srch) + 1);
        break;
      }
    }
    fclose(fp);
  }
  printf("Netlink number = %d\n", netlink_num);
  return netlink_num;
}


x86 assembly (clang, -O0):
<get_netlink_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe62(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1264 <get_netlink_num+0xe4>
jmp    11c9 <get_netlink_num+0x49>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e7 <get_netlink_num+0x67>
jmp    125b <get_netlink_num+0xdb>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x40,%esi
call   1070 <fgets@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1256 <get_netlink_num+0xd6>
lea    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x1,%rdi
call   10a0 <atoi@plt>
mov    %eax,-0xc(%rbp)
jmp    125b <get_netlink_num+0xdb>
jmp    11c9 <get_netlink_num+0x49>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xc(%rbp),%esi
lea    0xdb3(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_netlink_num>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    0x2e47(%rip),%rax
mov    (%rax),%r14d
add    $0xffffffff,%r14d
lea    0xe6d(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121c <get_netlink_num+0x9c>
mov    %rax,%rbx
mov    %rsp,%r15
lea    0xe43(%rip),%rbp
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1214 <get_netlink_num+0x94>
mov    %r15,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <get_netlink_num+0x40>
lea    0xe03(%rip),%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x1,%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdfe(%rip),%rdi
mov    %r14d,%esi
call   1060 <printf@plt>
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAX_LINKS = global i32 0
@.str = [12 x i8] c"netlink_num\00"
@.str.1 = [19 x i8] c"/proc/mwlan/config\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Netlink number = %d\0A\00"
define i32 @get_netlink_num() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca i8*
%5 = load i32, i32* @MAX_LINKS
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %2
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %1
%8 = load i32*, i32** %1
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %38
10: ; preds = %0
br label %11
11: ; preds = %34, %10
%12 = load i32*, i32** %1
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %1
%19 = call i32 @fgets(i8* %17, i32 64, i32* %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = call i64 @strncmp(i8* %20, i8* %21, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %16
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %2
br label %35
34: ; preds = %16
br label %11
35: ; preds = %26, %11
%36 = load i32*, i32** %1
%37 = call i32 @fclose(i32* %36)
br label %38
38: ; preds = %35, %0
%39 = load i32, i32* %2
%40 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@MAX_LINKS = global i32 0
@.str = [12 x i8] c"netlink_num\00"
@.str.1 = [19 x i8] c"/proc/mwlan/config\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Netlink number = %d\0A\00"
define i32 @get_netlink_num() {
%1 = alloca [64 x i8]
%2 = load i32, i32* @MAX_LINKS
%3 = add nsw i32 %2, -1
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %0, %10
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = call i32 @fgets(i8* %4, i32 64, i32* %5)
%12 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %10
%16 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @atoi(i8* %19)
br label %21
21: ; preds = %7, %15
%22 = phi i32 [ %20, %15 ], [ %3, %7 ]
%23 = call i32 @fclose(i32* %5)
br label %24
24: ; preds = %21, %0
%25 = phi i32 [ %22, %21 ], [ %3, %0 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %25)
ret i32 %25
}