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

/* Variables and functions */
int /*<<< orphan*/ close_end(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char const *, int *, int *, char **);
void listio() {
  const char *scan_fmt = NULL;
  char buffer[256];
  int major;
  int minor;
  char devname[8];
  FILE *iofp = fopen("/proc/diskstats", "r");
  printf("Available devices are:\n");
  scan_fmt = "%4d %4d %s";
  while (fgets(buffer, sizeof(buffer), iofp)) {
    sscanf(buffer, scan_fmt, &major, &minor, &devname);
    printf("   %s\n", devname);
  }
  close_end(0);
}


x86 assembly (clang, -O0):
<listio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xe96(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x128(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe98(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f7 <listio+0xa7>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x120(%rbp),%r8
lea    -0x114(%rbp),%rdx
lea    -0x118(%rbp),%rcx
call   1060 <sscanf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <listio+0x46>
xor    %edi,%edi
call   1040 <close_end@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listio>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xe88(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120a <listio+0xaa>
lea    0x10(%rsp),%rbx
lea    0x4(%rsp),%r12
mov    %rsp,%r13
lea    0x8(%rsp),%rbp
lea    0xe5a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
lea    0xe38(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1070 <sscanf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11d0 <listio+0x70>
xor    %edi,%edi
call   1050 <close_end@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/diskstats\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Available devices are:\0A\00"
@.str.3 = [11 x i8] c"%4d %4d %s\00"
@.str.4 = [7 x i8] c" %s\0A\00"
define void @listio() {
%1 = alloca i8*
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8 x i8]
%6 = alloca i32*
store i8* null, i8** %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %9
9: ; preds = %14, %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %6
%12 = call i64 @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = load i8*, i8** %1
%17 = bitcast [8 x i8]* %5 to i8**
%18 = call i32 @sscanf(i8* %15, i8* %16, i32* %3, i32* %4, i8** %17)
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %9
21: ; preds = %9
%22 = call i32 @close_end(i32 0)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/diskstats\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [11 x i8] c"%4d %4d %s\00"
@.str.4 = [7 x i8] c" %s\0A\00"
@str = [23 x i8] c"Available devices are:\00"
define void @listio() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%11 = call i64 @fgets(i8* %5, i32 256, i32* %9)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %0, %13
%14 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3, i8** %4)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %4)
%16 = call i64 @fgets(i8* %5, i32 256, i32* %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %13
18: ; preds = %13, %0
%19 = call i32 @close_end(i32 0)
ret void
}