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

/* Variables and functions */
struct piece *kill_piece(struct piece *, struct piece *);
scalar_t__ text_next(struct piece *, struct piece *);
int /*<<< orphan*/ text_step(struct piece **);
struct piece *arrange_pieces(struct piece *chain) {
  struct piece *ctx[2];
  struct piece *dead = 0;
  ctx[0] = chain, ctx[1] = 0;
  do {
    text_step(ctx);
    dead = kill_piece(dead, ctx[1]);
  } while (text_next(ctx[0], ctx[1]));
  dead = kill_piece(dead, ctx[0]);
  return dead;
}


x86 assembly (clang, -O0):
<arrange_pieces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <text_step@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <kill_piece@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <text_next@plt>
cmp    $0x0,%rax
jne    1154 <arrange_pieces+0x24>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <kill_piece@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrange_pieces>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <text_step@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <kill_piece@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1040 <text_next@plt>
test   %rax,%rax
jne    1150 <arrange_pieces+0x20>
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1030 <kill_piece@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.piece = type { i32 }
define %struct.piece* @arrange_pieces(%struct.piece* %0) {
%2 = alloca %struct.piece*
%3 = alloca [2 x %struct.piece*]
%4 = alloca %struct.piece*
store %struct.piece* %0, %struct.piece** %2
store %struct.piece* null, %struct.piece** %4
%5 = load %struct.piece*, %struct.piece** %2
%6 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 0
store %struct.piece* %5, %struct.piece** %6
%7 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 1
store %struct.piece* null, %struct.piece** %7
br label %8
8: ; preds = %15, %1
%9 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 0
%10 = call i32 @text_step(%struct.piece** %9)
%11 = load %struct.piece*, %struct.piece** %4
%12 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 1
%13 = load %struct.piece*, %struct.piece** %12
%14 = call %struct.piece* @kill_piece(%struct.piece* %11, %struct.piece* %13)
store %struct.piece* %14, %struct.piece** %4
br label %15
15: ; preds = %8
%16 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 0
%17 = load %struct.piece*, %struct.piece** %16
%18 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 1
%19 = load %struct.piece*, %struct.piece** %18
%20 = call i64 @text_next(%struct.piece* %17, %struct.piece* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %8, label %22
22: ; preds = %15
%23 = load %struct.piece*, %struct.piece** %4
%24 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %3, i64 0, i64 0
%25 = load %struct.piece*, %struct.piece** %24
%26 = call %struct.piece* @kill_piece(%struct.piece* %23, %struct.piece* %25)
store %struct.piece* %26, %struct.piece** %4
%27 = load %struct.piece*, %struct.piece** %4
ret %struct.piece* %27
}

LLVM IR (-O2):
%struct.piece = type { i32 }
define %struct.piece* @arrange_pieces(%struct.piece* %0) {
%2 = alloca [2 x %struct.piece*]
%3 = bitcast [2 x %struct.piece*]* %2 to i8*
%4 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %2, i64 0, i64 0
store %struct.piece* %0, %struct.piece** %4
%5 = getelementptr inbounds [2 x %struct.piece*], [2 x %struct.piece*]* %2, i64 0, i64 1
store %struct.piece* null, %struct.piece** %5
br label %6
6: ; preds = %6, %1
%7 = phi %struct.piece* [ null, %1 ], [ %10, %6 ]
%8 = call i32 @text_step(%struct.piece** %4)
%9 = load %struct.piece*, %struct.piece** %5
%10 = call %struct.piece* @kill_piece(%struct.piece* %7, %struct.piece* %9)
%11 = load %struct.piece*, %struct.piece** %4
%12 = load %struct.piece*, %struct.piece** %5
%13 = call i64 @text_next(%struct.piece* %11, %struct.piece* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = load %struct.piece*, %struct.piece** %4
%17 = call %struct.piece* @kill_piece(%struct.piece* %10, %struct.piece* %16)
ret %struct.piece* %17
}