#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 */
struct slab_stat {
  int dummy;
};
struct slab_info {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_slabinfo10(struct slab_info **, struct slab_stat *,
                     int /*<<< orphan*/ *);
int parse_slabinfo11(struct slab_info **, struct slab_stat *,
                     int /*<<< orphan*/ *);
int parse_slabinfo20(struct slab_info **, struct slab_stat *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ stderr;
int get_slabinfo(struct slab_info **list, struct slab_stat *stats) {
  FILE *slabfile;
  char buffer[100];
  int major, minor, ret = 0;
  slabfile = fopen("/proc/slabinfo", "r");
  if (!slabfile) {
    perror("fopen "
           "/proc/slabinfo");
    return 1;
  }
  if (!fgets(buffer, 100, slabfile)) {
    fprintf(stderr, "cannot read from slabinfo\n");
    return 1;
  }
  if (sscanf(buffer, "slabinfo - version: %d.%d", &major, &minor) != 2) {
    fprintf(stderr, "not the good old slabinfo we know\n");
    return 1;
  }
  if (major == 2) {
    ret = parse_slabinfo20(list, stats, slabfile);
  } else if (major == 1 && minor == 1) {
    ret = parse_slabinfo11(list, stats, slabfile);
  } else if (major == 1 && minor == 0) {
    ret = parse_slabinfo10(list, stats, slabfile);
  } else {
    fprintf(stderr, "unrecognizable slabinfo version\n");
    return 1;
  }
  fclose(slabfile);
  return ret;
}


x86 assembly (clang, -O0):
<get_slabinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x9c(%rbp)
lea    0xe54(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e7 <get_slabinfo+0x57>
lea    0xe2c(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <get_slabinfo+0x1b3>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    1226 <get_slabinfo+0x96>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <get_slabinfo+0x1b3>
lea    -0x90(%rbp),%rdi
lea    0xdfe(%rip),%rsi
lea    -0x94(%rbp),%rdx
lea    -0x98(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x2,%eax
je     1271 <get_slabinfo+0xe1>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <get_slabinfo+0x1b3>
cmpl   $0x2,-0x94(%rbp)
jne    129a <get_slabinfo+0x10a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <parse_slabinfo20@plt>
mov    %eax,-0x9c(%rbp)
jmp    1331 <get_slabinfo+0x1a1>
cmpl   $0x1,-0x94(%rbp)
jne    12d0 <get_slabinfo+0x140>
cmpl   $0x1,-0x98(%rbp)
jne    12d0 <get_slabinfo+0x140>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <parse_slabinfo11@plt>
mov    %eax,-0x9c(%rbp)
jmp    132c <get_slabinfo+0x19c>
cmpl   $0x1,-0x94(%rbp)
jne    1306 <get_slabinfo+0x176>
cmpl   $0x0,-0x98(%rbp)
jne    1306 <get_slabinfo+0x176>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <parse_slabinfo10@plt>
mov    %eax,-0x9c(%rbp)
jmp    1327 <get_slabinfo+0x197>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <get_slabinfo+0x1b3>
jmp    132c <get_slabinfo+0x19c>
jmp    1331 <get_slabinfo+0x1a1>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_slabinfo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe61(%rip),%rdi
lea    0xe52(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1288 <get_slabinfo+0xf8>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     120e <get_slabinfo+0x7e>
lea    0xe56(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1080 <sscanf@plt>
cmp    $0x2,%eax
jne    1220 <get_slabinfo+0x90>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jne    123c <get_slabinfo+0xac>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <parse_slabinfo20@plt>
jmp    1271 <get_slabinfo+0xe1>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
jmp    1230 <get_slabinfo+0xa0>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%ebp
jmp    127b <get_slabinfo+0xeb>
mov    0x8(%rsp),%ecx
cmp    $0x1,%eax
jne    125a <get_slabinfo+0xca>
cmp    $0x1,%ecx
jne    125a <get_slabinfo+0xca>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <parse_slabinfo11@plt>
jmp    1271 <get_slabinfo+0xe1>
cmp    $0x1,%eax
jne    129b <get_slabinfo+0x10b>
test   %ecx,%ecx
jne    129b <get_slabinfo+0x10b>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1090 <parse_slabinfo10@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd73(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%ebp
jmp    127b <get_slabinfo+0xeb>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
jmp    1230 <get_slabinfo+0xa0>

LLVM IR (-O0):
%struct.slab_info = type { i32 }
%struct.slab_stat = type { i32 }
@.str = [15 x i8] c"/proc/slabinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"fopen /proc/slabinfo\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"cannot read from slabinfo\0A\00"
@.str.4 = [26 x i8] c"slabinfo - version: %d.%d\00"
@.str.5 = [35 x i8] c"not the good old slabinfo we know\0A\00"
@.str.6 = [33 x i8] c"unrecognizable slabinfo version\0A\00"
define i32 @get_slabinfo(%struct.slab_info** %0, %struct.slab_stat* %1) {
%3 = alloca i32
%4 = alloca %struct.slab_info**
%5 = alloca %struct.slab_stat*
%6 = alloca i32*
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.slab_info** %0, %struct.slab_info*** %4
store %struct.slab_stat* %1, %struct.slab_stat** %5
store i32 0, i32* %10
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %70
16: ; preds = %2
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32 @fgets(i8* %17, i32 100, i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %70
24: ; preds = %16
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32* %8, i32* %9)
%27 = icmp ne i32 %26, 2
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %70
31: ; preds = %24
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load %struct.slab_info**, %struct.slab_info*** %4
%36 = load %struct.slab_stat*, %struct.slab_stat** %5
%37 = load i32*, i32** %6
%38 = call i32 @parse_slabinfo20(%struct.slab_info** %35, %struct.slab_stat* %36, i32* %37)
store i32 %38, i32* %10
br label %66
39: ; preds = %31
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load %struct.slab_info**, %struct.slab_info*** %4
%47 = load %struct.slab_stat*, %struct.slab_stat** %5
%48 = load i32*, i32** %6
%49 = call i32 @parse_slabinfo11(%struct.slab_info** %46, %struct.slab_stat* %47, i32* %48)
store i32 %49, i32* %10
br label %65
50: ; preds = %42, %39
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = load %struct.slab_info**, %struct.slab_info*** %4
%58 = load %struct.slab_stat*, %struct.slab_stat** %5
%59 = load i32*, i32** %6
%60 = call i32 @parse_slabinfo10(%struct.slab_info** %57, %struct.slab_stat* %58, i32* %59)
store i32 %60, i32* %10
br label %64
61: ; preds = %53, %50
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %70
64: ; preds = %56
br label %65
65: ; preds = %64, %45
br label %66
66: ; preds = %65, %34
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
%69 = load i32, i32* %10
store i32 %69, i32* %3
br label %70
70: ; preds = %66, %61, %28, %21, %14
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.slab_info = type { i32 }
%struct.slab_stat = type { i32 }
@.str = [15 x i8] c"/proc/slabinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"fopen /proc/slabinfo\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"cannot read from slabinfo\0A\00"
@.str.4 = [26 x i8] c"slabinfo - version: %d.%d\00"
@.str.5 = [35 x i8] c"not the good old slabinfo we know\0A\00"
@.str.6 = [33 x i8] c"unrecognizable slabinfo version\0A\00"
define i32 @get_slabinfo(%struct.slab_info** %0, %struct.slab_stat* %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %48
13: ; preds = %2
%14 = call i32 @fgets(i8* %6, i32 100, i32* %9)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %48
19: ; preds = %13
%20 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%21 = icmp eq i32 %20, 2
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %48
25: ; preds = %19
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @parse_slabinfo20(%struct.slab_info** %0, %struct.slab_stat* %1, i32* %9)
br label %45
30: ; preds = %25
%31 = icmp eq i32 %26, 1
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 1
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @parse_slabinfo11(%struct.slab_info** %0, %struct.slab_stat* %1, i32* %9)
br label %45
37: ; preds = %30
%38 = icmp eq i32 %32, 0
%39 = select i1 %31, i1 %38, i1 false
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @parse_slabinfo10(%struct.slab_info** %0, %struct.slab_stat* %1, i32* %9)
br label %45
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %48
45: ; preds = %35, %40, %28
%46 = phi i32 [ %29, %28 ], [ %36, %35 ], [ %41, %40 ]
%47 = call i32 @fclose(i32* %9)
br label %48
48: ; preds = %45, %42, %22, %16, %11
%49 = phi i32 [ 1, %22 ], [ %46, %45 ], [ 1, %42 ], [ 1, %16 ], [ 1, %11 ]
ret i32 %49
}