#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int print_mounts() {
  FILE *f;
  int length;
  char buffer[100];
  f = fopen("/proc/mounts", "r");
  if (!f) {
    fprintf(stdout, "could not open /proc/mounts\n");
    return -1;
  }
  do {
    length = fread(buffer, 1, 100, f);
    if (length > 0)
      fwrite(buffer, 1, length, stdout);
  } while (length > 0);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<print_mounts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <print_mounts+0x4e>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <print_mounts+0xb0>
jmp    11a3 <print_mounts+0x53>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x64,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e1 <print_mounts+0x91>
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    0x2e0b(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    11e6 <print_mounts+0x96>
cmpl   $0x0,-0x14(%rbp)
jg     11a3 <print_mounts+0x53>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mounts>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xea0(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d7 <print_mounts+0x87>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11cb <print_mounts+0x7b>
mov    0x2e4c(%rip),%r15
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11a0 <print_mounts+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11f1 <print_mounts+0xa1>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [29 x i8] c"could not open /proc/mounts\0A\00"
define i32 @print_mounts() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @stdout
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %30
11: ; preds = %0
br label %12
12: ; preds = %24, %11
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32 @fread(i8* %13, i32 1, i32 100, i32* %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* %3
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite(i8* %19, i32 1, i32 %20, i32 %21)
br label %23
23: ; preds = %18, %12
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = icmp sgt i32 %25, 0
br i1 %26, label %12, label %27
27: ; preds = %24
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %1
br label %30
30: ; preds = %27, %8
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [29 x i8] c"could not open /proc/mounts\0A\00"
define i32 @print_mounts() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @fread(i8* %2, i32 1, i32 100, i32* %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %11, label %17
8: ; preds = %0
%9 = load i32, i32* @stdout
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %19
11: ; preds = %5, %11
%12 = phi i32 [ %15, %11 ], [ %6, %5 ]
%13 = load i32, i32* @stdout
%14 = call i32 @fwrite(i8* %2, i32 1, i32 %12, i32 %13)
%15 = call i32 @fread(i8* %2, i32 1, i32 100, i32* %3)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %11, label %17
17: ; preds = %11, %5
%18 = call i32 @fclose(i32* %3)
br label %19
19: ; preds = %17, %8
%20 = phi i32 [ 0, %17 ], [ -1, %8 ]
ret i32 %20
}