#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 event {
  int dummy;
};
struct diagram {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
struct event *get_first_event(struct diagram *);
struct event *get_next_event(struct event *);
int /*<<< orphan*/ print_event(struct event *);
int /*<<< orphan*/ puts(char *);
void print_events(struct diagram *diag) {
  assert(diag != NULL);
  puts("events:");
  struct event *e = get_first_event(diag);
  while (e != NULL) {
    print_event(e);
    e = get_next_event(e);
  }
}


x86 assembly (clang, -O0):
<print_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1070 <get_first_event@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ad <print_events+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <print_event@plt>
mov    -0x10(%rbp),%rdi
call   1050 <get_next_event@plt>
mov    %rax,-0x10(%rbp)
jmp    1187 <print_events+0x37>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_events>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1060 <assert@plt>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <get_first_event@plt>
test   %rax,%rax
je     1198 <print_events+0x48>
mov    %rax,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <print_event@plt>
mov    %rbx,%rdi
call   1050 <get_next_event@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <print_events+0x30>
pop    %rbx
ret

LLVM IR (-O0):
%struct.diagram = type { i32 }
%struct.event = type { i32 }
@.str = [8 x i8] c"events:\00"
define void @print_events(%struct.diagram* %0) {
%2 = alloca %struct.diagram*
%3 = alloca %struct.event*
store %struct.diagram* %0, %struct.diagram** %2
%4 = load %struct.diagram*, %struct.diagram** %2
%5 = icmp ne %struct.diagram* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load %struct.diagram*, %struct.diagram** %2
%10 = call %struct.event* @get_first_event(%struct.diagram* %9)
store %struct.event* %10, %struct.event** %3
br label %11
11: ; preds = %14, %1
%12 = load %struct.event*, %struct.event** %3
%13 = icmp ne %struct.event* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load %struct.event*, %struct.event** %3
%16 = call i32 @print_event(%struct.event* %15)
%17 = load %struct.event*, %struct.event** %3
%18 = call %struct.event* @get_next_event(%struct.event* %17)
store %struct.event* %18, %struct.event** %3
br label %11
19: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.diagram = type { i32 }
%struct.event = type { i32 }
@.str = [8 x i8] c"events:\00"
define void @print_events(%struct.diagram* %0) {
%2 = icmp ne %struct.diagram* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = tail call %struct.event* @get_first_event(%struct.diagram* %0)
%7 = icmp eq %struct.event* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1, %8
%9 = phi %struct.event* [ %11, %8 ], [ %6, %1 ]
%10 = tail call i32 @print_event(%struct.event* %9)
%11 = tail call %struct.event* @get_next_event(%struct.event* %9)
%12 = icmp eq %struct.event* %11, null
br i1 %12, label %13, label %8
13: ; preds = %8, %1
ret void
}