#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ FSETLOCKING_BYCALLER;
int /*<<< orphan*/ __fsetlocking(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strerror(scalar_t__);
void get_interface(unsigned int iface, char *ifc) {
  unsigned int line = 0;
  FILE *f;
  char buf[256], more[256];
  *ifc = 0;
  iface++;
  f = fopen("/proc/net/dev", "rte");
  if (f == NULL) {
    if (errno != ENOENT)
      fprintf(stderr, "Can't open /proc/net/dev: %s\n", strerror(errno));
    return;
  }
  __fsetlocking(f, FSETLOCKING_BYCALLER);
  while (fgets(buf, sizeof(buf), f)) {
    if (line == iface) {
      char *c;
      sscanf(buf, "%16s: %256s\n", ifc, more);
      c = strchr(ifc, ':');
      if (c)
        *c = 0;
      fclose(f);
      return;
    }
    line++;
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<get_interface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121d <get_interface+0x9d>
mov    0x2e06(%rip),%rax
mov    (%rax),%rax
mov    0x2de4(%rip),%rcx
cmp    (%rcx),%rax
je     1218 <get_interface+0x98>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x22c(%rbp),%edi
mov    %rax,%rdx
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12ca <get_interface+0x14a>
mov    -0x20(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
call   1070 <__fsetlocking@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12c1 <get_interface+0x141>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    12b3 <get_interface+0x133>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x220(%rbp),%rcx
lea    0xdbd(%rip),%rsi
call   1080 <sscanf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
je     12a5 <get_interface+0x125>
mov    -0x228(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12ca <get_interface+0x14a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122f <get_interface+0xaf>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_interface>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movb   $0x0,(%rsi)
lea    0xe64(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fc <get_interface+0x7c>
mov    %rax,%rbx
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <__fsetlocking@plt>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     126d <get_interface+0xed>
add    $0x2,%ebp
mov    %rsp,%r15
add    $0xffffffff,%ebp
je     123e <get_interface+0xbe>
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11e0 <get_interface+0x60>
jmp    126d <get_interface+0xed>
mov    0x2dd5(%rip),%rax
mov    (%rax),%rdi
mov    0x2db3(%rip),%rax
cmp    (%rax),%rdi
je     1275 <get_interface+0xf5>
mov    0x2dc7(%rip),%rax
mov    (%rax),%ebx
call   10a0 <strerror@plt>
lea    0xdeb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>
lea    0xdeb(%rip),%rsi
mov    %rsp,%rdi
lea    0x100(%rsp),%rcx
mov    %r14,%rdx
call   1080 <sscanf@plt>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     126d <get_interface+0xed>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [4 x i8] c"rte\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Can't open /proc/net/dev: %s\0A\00"
@FSETLOCKING_BYCALLER = global i32 0
@.str.3 = [13 x i8] c"%16s: %256s\0A\00"
define void @get_interface(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%10 = load i8*, i8** %4
store i8 0, i8* %10
%11 = load i32, i32* %3
%12 = add i32 %11, 1
store i32 %12, i32* %3
%13 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %26
16: ; preds = %2
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOENT
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %20, %16
br label %59
26: ; preds = %2
%27 = load i32*, i32** %6
%28 = load i32, i32* @FSETLOCKING_BYCALLER
%29 = call i32 @__fsetlocking(i32* %27, i32 %28)
br label %30
30: ; preds = %53, %26
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i64 @fgets(i8* %31, i32 256, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %56
35: ; preds = %30
%36 = load i32, i32* %5
%37 = load i32, i32* %3
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %53
39: ; preds = %35
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %4
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%43 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %41, i8* %42)
%44 = load i8*, i8** %4
%45 = call i8* @strchr(i8* %44, i8 signext 58)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = load i8*, i8** %9
store i8 0, i8* %49
br label %50
50: ; preds = %48, %39
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
br label %59
53: ; preds = %35
%54 = load i32, i32* %5
%55 = add i32 %54, 1
store i32 %55, i32* %5
br label %30
56: ; preds = %30
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %56, %50, %25
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [4 x i8] c"rte\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Can't open /proc/net/dev: %s\0A\00"
@FSETLOCKING_BYCALLER = global i32 0
@.str.3 = [13 x i8] c"%16s: %256s\0A\00"
define void @get_interface(i32 %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8 0, i8* %1
%7 = add i32 %0, 1
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %39, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i8* @strerror(i64 %11)
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %39
18: ; preds = %2
%19 = load i32, i32* @FSETLOCKING_BYCALLER
%20 = tail call i32 @__fsetlocking(i32* %8, i32 %19)
%21 = call i64 @fgets(i8* %5, i32 256, i32* %8)
%22 = icmp eq i64 %21, 0
br i1 %22, label %37, label %27
23: ; preds = %27
%24 = add i32 %28, 1
%25 = call i64 @fgets(i8* %5, i32 256, i32* %8)
%26 = icmp eq i64 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %18, %23
%28 = phi i32 [ %24, %23 ], [ 0, %18 ]
%29 = icmp eq i32 %28, %7
br i1 %29, label %30, label %23
30: ; preds = %27
%31 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %6)
%32 = call i8* @strchr(i8* %1, i8 signext 58)
%33 = icmp eq i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %30
store i8 0, i8* %32
br label %35
35: ; preds = %34, %30
%36 = call i32 @fclose(i32* %8)
br label %39
37: ; preds = %23, %18
%38 = call i32 @fclose(i32* %8)
br label %39
39: ; preds = %10, %14, %37, %35
ret void
}