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

/* Variables and functions */
struct mntent *getmntent_r(int /*<<< orphan*/ *, struct mntent *, char *, int);
scalar_t__ malloc(int);
struct mntent *getmntent(FILE *stream) {
  static struct mntent m;
  static char *getmntent_buffer;
  if (!getmntent_buffer) {
    getmntent_buffer = (char *)malloc(4096);
    if (!getmntent_buffer)
      return NULL;
  }
  return getmntent_r(stream, &m, getmntent_buffer, 4096);
}


x86 assembly (clang, -O0):
<getmntent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2f0c(%rip)
jne    116b <getmntent+0x4b>
mov    $0x1000,%edi
call   1040 <malloc@plt>
mov    %rax,0x2ef5(%rip)
cmpq   $0x0,0x2eed(%rip)
jne    1166 <getmntent+0x46>
movq   $0x0,-0x8(%rbp)
jmp    118b <getmntent+0x6b>
jmp    116b <getmntent+0x4b>
mov    -0x10(%rbp),%rdi
mov    0x2eca(%rip),%rdx
lea    0x2ebb(%rip),%rsi
mov    $0x1000,%ecx
call   1030 <getmntent_r@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmntent>:
push   %rbx
mov    %rdi,%rbx
mov    0x2f15(%rip),%rdx
test   %rdx,%rdx
jne    1149 <getmntent+0x29>
mov    $0x1000,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    %rax,0x2efc(%rip)
test   %rax,%rax
je     115e <getmntent+0x3e>
lea    0x2ee8(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1000,%ecx
pop    %rbx
jmp    1030 <getmntent_r@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.mntent = type { i32 }
@getmntent.m = internal global %struct.mntent zeroinitializer
@getmntent.getmntent_buffer = internal global i8* null
define %struct.mntent* @getmntent(i32* %0) {
%2 = alloca %struct.mntent*
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i8*, i8** @getmntent.getmntent_buffer
%5 = icmp ne i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = call i64 @malloc(i32 4096)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** @getmntent.getmntent_buffer
%9 = load i8*, i8** @getmntent.getmntent_buffer
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %6
store %struct.mntent* null, %struct.mntent** %2
br label %17
12: ; preds = %6
br label %13
13: ; preds = %12, %1
%14 = load i32*, i32** %3
%15 = load i8*, i8** @getmntent.getmntent_buffer
%16 = call %struct.mntent* @getmntent_r(i32* %14, %struct.mntent* @getmntent.m, i8* %15, i32 4096)
store %struct.mntent* %16, %struct.mntent** %2
br label %17
17: ; preds = %13, %11
%18 = load %struct.mntent*, %struct.mntent** %2
ret %struct.mntent* %18
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@getmntent.m = internal global %struct.mntent zeroinitializer
@getmntent.getmntent_buffer = internal unnamed_addr global i8* null
define %struct.mntent* @getmntent(i32* %0) {
%2 = load i8*, i8** @getmntent.getmntent_buffer
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i64 @malloc(i32 4096)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** @getmntent.getmntent_buffer
%7 = icmp eq i64 %5, 0
br i1 %7, label %11, label %8
8: ; preds = %4, %1
%9 = phi i8* [ %6, %4 ], [ %2, %1 ]
%10 = tail call %struct.mntent* @getmntent_r(i32* %0, %struct.mntent* @getmntent.m, i8* %9, i32 4096)
br label %11
11: ; preds = %4, %8
%12 = phi %struct.mntent* [ %10, %8 ], [ null, %4 ]
ret %struct.mntent* %12
}