#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int get_dev(int number, char *dev) {
  number += 2;
  FILE *fp;
  fp = fopen("/proc/net/dev", "r");
  if (fp == NULL) {
    printf("File could not be opened\nIp address could not be determined\n");
  }
  for (unsigned i = 0; i < number; i++)
    while (fgetc(fp) != '\n')
      ;
  for (int i = 0; i < 10; i++) {
    dev[i] = fgetc(fp);
    if (dev[i] == ':') {
      dev[i] = 0;
      break;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<get_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
lea    0xea1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <get_dev+0x46>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11cb <get_dev+0x8b>
jmp    119e <get_dev+0x5e>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11b8 <get_dev+0x78>
jmp    119e <get_dev+0x5e>
jmp    11bd <get_dev+0x7d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <get_dev+0x4d>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    122b <get_dev+0xeb>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1218 <get_dev+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122b <get_dev+0xeb>
jmp    121d <get_dev+0xdd>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d2 <get_dev+0x92>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
add    $0x2,%r15d
lea    0xea8(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1178 <get_dev+0x38>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
test   %r15d,%r15d
je     1194 <get_dev+0x54>
xor    %ebp,%ebp
nop
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%al
jne    1180 <get_dev+0x40>
add    $0x1,%ebp
cmp    %r15d,%ebp
jne    1180 <get_dev+0x40>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,(%r14)
cmp    $0x3a,%al
jne    11aa <get_dev+0x6a>
xor    %ecx,%ecx
jmp    126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x1(%r14)
mov    $0x1,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x2(%r14)
mov    $0x2,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x3(%r14)
mov    $0x3,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x4(%r14)
mov    $0x4,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x5(%r14)
mov    $0x5,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x6(%r14)
mov    $0x6,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x7(%r14)
mov    $0x7,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x8(%r14)
mov    $0x8,%ecx
cmp    $0x3a,%al
je     126f <get_dev+0x12f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %al,0x9(%r14)
mov    $0x9,%ecx
cmp    $0x3a,%al
jne    1274 <get_dev+0x134>
movb   $0x0,(%r14,%rcx,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [61 x i8] c"File could not be opened\0AIp address could not be determined\0A\00"
define i32 @get_dev(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 2
store i32 %9, i32* %3
%10 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
store i32 0, i32* %6
br label %16
16: ; preds = %28, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %3
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
br label %21
21: ; preds = %26, %20
%22 = load i32*, i32** %5
%23 = call signext i8 @fgetc(i32* %22)
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %21
br label %21
27: ; preds = %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %16
31: ; preds = %16
store i32 0, i32* %7
br label %32
32: ; preds = %55, %31
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 10
br i1 %34, label %35, label %58
35: ; preds = %32
%36 = load i32*, i32** %5
%37 = call signext i8 @fgetc(i32* %36)
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
%42 = load i8*, i8** %4
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 58
br i1 %48, label %49, label %54
49: ; preds = %35
%50 = load i8*, i8** %4
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 0, i8* %53
br label %58
54: ; preds = %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %32
58: ; preds = %49, %32
%59 = load i32*, i32** %5
%60 = call i32 @fclose(i32* %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@str = [60 x i8] c"File could not be opened\0AIp address could not be determined\00"
define i32 @get_dev(i32 %0, i8* nocapture writeonly %1) {
%3 = add i32 %0, 2
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = icmp eq i32 %3, 0
br i1 %9, label %12, label %10
10: ; preds = %8, %18
%11 = phi i32 [ %19, %18 ], [ 0, %8 ]
br label %15
12: ; preds = %18, %8
%13 = tail call signext i8 @fgetc(i32* %4)
store i8 %13, i8* %1
%14 = icmp eq i8 %13, 58
br i1 %14, label %21, label %24
15: ; preds = %10, %15
%16 = tail call signext i8 @fgetc(i32* %4)
%17 = icmp eq i8 %16, 10
br i1 %17, label %18, label %15
18: ; preds = %15
%19 = add nuw i32 %11, 1
%20 = icmp eq i32 %19, %3
br i1 %20, label %12, label %10
21: ; preds = %56, %52, %48, %44, %40, %36, %32, %28, %24, %12
%22 = phi i64 [ 0, %12 ], [ 1, %24 ], [ 2, %28 ], [ 3, %32 ], [ 4, %36 ], [ 5, %40 ], [ 6, %44 ], [ 7, %48 ], [ 8, %52 ], [ 9, %56 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
br label %60
24: ; preds = %12
%25 = tail call signext i8 @fgetc(i32* %4)
%26 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %25, i8* %26
%27 = icmp eq i8 %25, 58
br i1 %27, label %21, label %28
28: ; preds = %24
%29 = tail call signext i8 @fgetc(i32* %4)
%30 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %29, i8* %30
%31 = icmp eq i8 %29, 58
br i1 %31, label %21, label %32
32: ; preds = %28
%33 = tail call signext i8 @fgetc(i32* %4)
%34 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %33, i8* %34
%35 = icmp eq i8 %33, 58
br i1 %35, label %21, label %36
36: ; preds = %32
%37 = tail call signext i8 @fgetc(i32* %4)
%38 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %37, i8* %38
%39 = icmp eq i8 %37, 58
br i1 %39, label %21, label %40
40: ; preds = %36
%41 = tail call signext i8 @fgetc(i32* %4)
%42 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %41, i8* %42
%43 = icmp eq i8 %41, 58
br i1 %43, label %21, label %44
44: ; preds = %40
%45 = tail call signext i8 @fgetc(i32* %4)
%46 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %45, i8* %46
%47 = icmp eq i8 %45, 58
br i1 %47, label %21, label %48
48: ; preds = %44
%49 = tail call signext i8 @fgetc(i32* %4)
%50 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %49, i8* %50
%51 = icmp eq i8 %49, 58
br i1 %51, label %21, label %52
52: ; preds = %48
%53 = tail call signext i8 @fgetc(i32* %4)
%54 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %53, i8* %54
%55 = icmp eq i8 %53, 58
br i1 %55, label %21, label %56
56: ; preds = %52
%57 = tail call signext i8 @fgetc(i32* %4)
%58 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %57, i8* %58
%59 = icmp eq i8 %57, 58
br i1 %59, label %21, label %60
60: ; preds = %56, %21
%61 = tail call i32 @fclose(i32* %4)
ret i32 0
}