#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 */
long atol(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
long get_interface_t(char *interface) {
  char filename[100];
  sprintf(filename, "/sys/class/net/%s/statistics/tx_bytes", interface);
  if (fopen(filename, "r") == NULL)
    return 0;
  char buffer[25];
  FILE *info = fopen(filename, "r");
  fgets(buffer, 24, info);
  fclose(info);
  return atol(buffer);
}


x86 assembly (clang, -O0):
<get_interface_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe92(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
cmp    $0x0,%rax
jne    119a <get_interface_t+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <get_interface_t+0x95>
lea    -0x80(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x18,%esi
call   1040 <fgets@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_interface_t>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rdx
lea    0xe9c(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11be <get_interface_t+0x6e>
lea    0xe9a(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x18,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1050 <atol@plt>
jmp    11c0 <get_interface_t+0x70>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/sys/class/net/%s/statistics/tx_bytes\00"
@.str.1 = [2 x i8] c"r\00"
define i64 @get_interface_t(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca [25 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 0, i64* %2
br label %24
14: ; preds = %1
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32 @fgets(i8* %17, i32 24, i32* %18)
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
%22 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%23 = call i64 @atol(i8* %22)
store i64 %23, i64* %2
br label %24
24: ; preds = %14, %13
%25 = load i64, i64* %2
ret i64 %25
}

LLVM IR (-O2):
@.str = [38 x i8] c"/sys/class/net/%s/statistics/tx_bytes\00"
@.str.1 = [2 x i8] c"r\00"
define i64 @get_interface_t(i8* %0) {
%2 = alloca [100 x i8]
%3 = alloca [25 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%10 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @fgets(i8* %9, i32 24, i32* %10)
%12 = call i32 @fclose(i32* %10)
%13 = call i64 @atol(i8* %9)
br label %14
14: ; preds = %1, %8
%15 = phi i64 [ %13, %8 ], [ 0, %1 ]
ret i64 %15
}