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

/* Variables and functions */
struct section *section_next(struct section *);
struct section *section_last(struct section *section) {
  struct section *next = section;
  if (!section)
    return NULL;
  do {
    section = next;
    next = section_next(section);
  } while (next);
  return section;
}


x86 assembly (clang, -O0):
<section_last>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113c <section_last+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1169 <section_last+0x59>
jmp    1141 <section_last+0x31>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <section_next@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1141 <section_last+0x31>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<section_last>:
push   %rbx
test   %rdi,%rdi
je     1132 <section_last+0x22>
mov    %rdi,%rax
nopl   0x0(%rax)
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <section_next@plt>
test   %rax,%rax
jne    1120 <section_last+0x10>
jmp    1134 <section_last+0x24>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.section = type { i32 }
define %struct.section* @section_last(%struct.section* %0) {
%2 = alloca %struct.section*
%3 = alloca %struct.section*
%4 = alloca %struct.section*
store %struct.section* %0, %struct.section** %3
%5 = load %struct.section*, %struct.section** %3
store %struct.section* %5, %struct.section** %4
%6 = load %struct.section*, %struct.section** %3
%7 = icmp ne %struct.section* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store %struct.section* null, %struct.section** %2
br label %19
9: ; preds = %1
br label %10
10: ; preds = %14, %9
%11 = load %struct.section*, %struct.section** %4
store %struct.section* %11, %struct.section** %3
%12 = load %struct.section*, %struct.section** %3
%13 = call %struct.section* @section_next(%struct.section* %12)
store %struct.section* %13, %struct.section** %4
br label %14
14: ; preds = %10
%15 = load %struct.section*, %struct.section** %4
%16 = icmp ne %struct.section* %15, null
br i1 %16, label %10, label %17
17: ; preds = %14
%18 = load %struct.section*, %struct.section** %3
store %struct.section* %18, %struct.section** %2
br label %19
19: ; preds = %17, %8
%20 = load %struct.section*, %struct.section** %2
ret %struct.section* %20
}

LLVM IR (-O2):
%struct.section = type { i32 }
define %struct.section* @section_last(%struct.section* %0) {
%2 = icmp eq %struct.section* %0, null
br i1 %2, label %7, label %3
3: ; preds = %1, %3
%4 = phi %struct.section* [ %5, %3 ], [ %0, %1 ]
%5 = tail call %struct.section* @section_next(%struct.section* %4)
%6 = icmp eq %struct.section* %5, null
br i1 %6, label %7, label %3
7: ; preds = %3, %1
%8 = phi %struct.section* [ null, %1 ], [ %4, %3 ]
ret %struct.section* %8
}