#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 */
scalar_t__ fill_buffer(char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_entry(int /*<<< orphan*/, struct utmp *);
int /*<<< orphan*/ stdout;
void read_from_stdin() {
  char *buffer;
  if ((buffer = malloc((sizeof(struct utmp)))) == NULL) {
    perror("malloc");
    return;
  }
  while (fill_buffer(buffer, (sizeof(struct utmp))) > 0) {
    print_entry(stdout, (struct utmp *)buffer);
  }
  free(buffer);
}


x86 assembly (clang, -O0):
<read_from_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1181 <read_from_stdin+0x31>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
jmp    11be <read_from_stdin+0x6e>
jmp    1186 <read_from_stdin+0x36>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1040 <fill_buffer@plt>
cmp    $0x0,%rax
jle    11b5 <read_from_stdin+0x65>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1070 <print_entry@plt>
jmp    1186 <read_from_stdin+0x36>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_stdin>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ac <read_from_stdin+0x5c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1040 <fill_buffer@plt>
test   %rax,%rax
jle    119d <read_from_stdin+0x4d>
mov    0x2e61(%rip),%r14
nop
mov    (%r14),%edi
mov    %rbx,%rsi
call   1070 <print_entry@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <fill_buffer@plt>
test   %rax,%rax
jg     1180 <read_from_stdin+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
lea    0xe4d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <perror@plt>

LLVM IR (-O0):
%struct.utmp = type { i32 }
@.str = [7 x i8] c"malloc\00"
@stdout = global i32 0
define void @read_from_stdin() {
%1 = alloca i8*
%2 = call i8* @malloc(i32 4)
store i8* %2, i8** %1
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
6: ; preds = %0
br label %7
7: ; preds = %11, %6
%8 = load i8*, i8** %1
%9 = call i64 @fill_buffer(i8* %8, i32 4)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* @stdout
%13 = load i8*, i8** %1
%14 = bitcast i8* %13 to %struct.utmp*
%15 = call i32 @print_entry(i32 %12, %struct.utmp* %14)
br label %7
16: ; preds = %7
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
br label %19
19: ; preds = %16, %4
ret void
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@.str = [7 x i8] c"malloc\00"
@stdout = global i32 0
define void @read_from_stdin() {
%1 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%2 = icmp eq i8* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i64 @fill_buffer(i8* %1, i32 4)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = bitcast i8* %1 to %struct.utmp*
br label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
10: ; preds = %6, %10
%11 = load i32, i32* @stdout
%12 = tail call i32 @print_entry(i32 %11, %struct.utmp* %7)
%13 = tail call i64 @fill_buffer(i8* %1, i32 4)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %10, label %15
15: ; preds = %10, %3
%16 = tail call i32 @free(i8* %1)
br label %17
17: ; preds = %15, %8
ret void
}