#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 utmp {
  int dummy;
};

/* Variables and functions */
struct utmp *malloc(int);
int read(int, char *, int);
struct utmp *__getutent(int utmp_fd) {
  static struct utmp *utmp;
  if (utmp == NULL) {
    utmp = malloc(sizeof(struct utmp));
    if (utmp == NULL)
      return NULL;
  }
  if (read(utmp_fd, (char *)utmp, sizeof(struct utmp)) != sizeof(struct utmp))
    return NULL;
  return utmp;
}


x86 assembly (clang, -O0):
<__getutent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpq   $0x0,0x2f05(%rip)
jne    116a <__getutent+0x4a>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,0x2eee(%rip)
cmpq   $0x0,0x2ee6(%rip)
jne    1165 <__getutent+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <__getutent+0x82>
jmp    116a <__getutent+0x4a>
mov    -0xc(%rbp),%edi
mov    0x2ec4(%rip),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
cltq
cmp    $0x4,%rax
je     1197 <__getutent+0x77>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <__getutent+0x82>
mov    0x2e9a(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__getutent>:
push   %rbx
mov    %edi,%ebx
mov    0x2f0e(%rip),%rsi
test   %rsi,%rsi
jne    1148 <__getutent+0x28>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rsi
mov    %rax,0x2ef5(%rip)
test   %rax,%rax
je     1162 <__getutent+0x42>
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <read@plt>
cmp    $0x4,%eax
jne    1162 <__getutent+0x42>
mov    0x2ed8(%rip),%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.utmp = type { i32 }
@__getutent.utmp = internal global %struct.utmp* null
define %struct.utmp* @__getutent(i32 %0) {
%2 = alloca %struct.utmp*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load %struct.utmp*, %struct.utmp** @__getutent.utmp
%5 = icmp eq %struct.utmp* %4, null
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = call %struct.utmp* @malloc(i32 4)
store %struct.utmp* %7, %struct.utmp** @__getutent.utmp
%8 = load %struct.utmp*, %struct.utmp** @__getutent.utmp
%9 = icmp eq %struct.utmp* %8, null
br i1 %9, label %10, label %11
10: ; preds = %6
store %struct.utmp* null, %struct.utmp** %2
br label %22
11: ; preds = %6
br label %12
12: ; preds = %11, %1
%13 = load i32, i32* %3
%14 = load %struct.utmp*, %struct.utmp** @__getutent.utmp
%15 = bitcast %struct.utmp* %14 to i8*
%16 = call i32 @read(i32 %13, i8* %15, i32 4)
%17 = sext i32 %16 to i64
%18 = icmp ne i64 %17, 4
br i1 %18, label %19, label %20
19: ; preds = %12
store %struct.utmp* null, %struct.utmp** %2
br label %22
20: ; preds = %12
%21 = load %struct.utmp*, %struct.utmp** @__getutent.utmp
store %struct.utmp* %21, %struct.utmp** %2
br label %22
22: ; preds = %20, %19, %10
%23 = load %struct.utmp*, %struct.utmp** %2
ret %struct.utmp* %23
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@__getutent.utmp = internal unnamed_addr global %struct.utmp* null
define %struct.utmp* @__getutent(i32 %0) {
%2 = load %struct.utmp*, %struct.utmp** @__getutent.utmp
%3 = icmp eq %struct.utmp* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call %struct.utmp* @malloc(i32 4)
store %struct.utmp* %5, %struct.utmp** @__getutent.utmp
%6 = icmp eq %struct.utmp* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4, %1
%8 = phi %struct.utmp* [ %5, %4 ], [ %2, %1 ]
%9 = bitcast %struct.utmp* %8 to i8*
%10 = tail call i32 @read(i32 %0, i8* %9, i32 4)
%11 = icmp eq i32 %10, 4
%12 = load %struct.utmp*, %struct.utmp** @__getutent.utmp
%13 = select i1 %11, %struct.utmp* %12, %struct.utmp* null
br label %14
14: ; preds = %7, %4
%15 = phi %struct.utmp* [ null, %4 ], [ %13, %7 ]
ret %struct.utmp* %15
}