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

/* Variables and functions */
int /*<<< orphan*/ apilar(struct _Pila *, int /*<<< orphan*/);
int /*<<< orphan*/ desapilar(struct _Pila *);
int /*<<< orphan*/ pilavacia(struct _Pila *);
scalar_t__ tope(struct _Pila *);
void intercalar(struct _Pila *p1, struct _Pila *p2, struct _Pila *p3) {
  while (!pilavacia(p1) && !pilavacia(p2)) {
    if (tope(p1) < tope(p2)) {
      apilar(p3, desapilar(p1));
    } else {
      apilar(p3, desapilar(p2));
    }
  }
  if (!pilavacia(p1)) {
    while (!pilavacia(p1)) {
      apilar(p3, desapilar(p1));
    }
  } else {
    while (!pilavacia(p2)) {
      apilar(p3, desapilar(p2));
    }
  }
}


x86 assembly (clang, -O0):
<intercalar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <pilavacia@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    1181 <intercalar+0x41>
mov    -0x10(%rbp),%rdi
call   1040 <pilavacia@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1191 <intercalar+0x51>
jmp    11f9 <intercalar+0xb9>
mov    -0x8(%rbp),%rdi
call   1050 <tope@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <tope@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    11d8 <intercalar+0x98>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <desapilar@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
jmp    11f4 <intercalar+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <desapilar@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
jmp    1154 <intercalar+0x14>
mov    -0x8(%rbp),%rdi
call   1040 <pilavacia@plt>
cmp    $0x0,%eax
jne    1254 <intercalar+0x114>
jmp    1210 <intercalar+0xd0>
mov    -0x8(%rbp),%rdi
call   1040 <pilavacia@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122e <intercalar+0xee>
jmp    124f <intercalar+0x10f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <desapilar@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
jmp    1210 <intercalar+0xd0>
jmp    129d <intercalar+0x15d>
jmp    1259 <intercalar+0x119>
mov    -0x10(%rbp),%rdi
call   1040 <pilavacia@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1277 <intercalar+0x137>
jmp    1298 <intercalar+0x158>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <desapilar@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
jmp    1259 <intercalar+0x119>
jmp    129d <intercalar+0x15d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intercalar>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1040 <pilavacia@plt>
test   %eax,%eax
jne    11a6 <intercalar+0x66>
mov    %r12,%rdi
call   1040 <pilavacia@plt>
test   %eax,%eax
jne    11a6 <intercalar+0x66>
mov    %r15,%rdi
call   1050 <tope@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <tope@plt>
cmp    %rax,%rbx
mov    %r12,%rdi
cmovl  %r15,%rdi
call   1030 <desapilar@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
mov    %r15,%rdi
jmp    1160 <intercalar+0x20>
mov    %r15,%rdi
call   1040 <pilavacia@plt>
test   %eax,%eax
je     11f2 <intercalar+0xb2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <pilavacia@plt>
test   %eax,%eax
jne    11fe <intercalar+0xbe>
mov    %r12,%rdi
call   1030 <desapilar@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
jmp    11c0 <intercalar+0x80>
mov    %r15,%rdi
call   1030 <desapilar@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <apilar@plt>
mov    %r15,%rdi
call   1040 <pilavacia@plt>
test   %eax,%eax
je     11e0 <intercalar+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct._Pila = type { i32 }
define void @intercalar(%struct._Pila* %0, %struct._Pila* %1, %struct._Pila* %2) {
%4 = alloca %struct._Pila*
%5 = alloca %struct._Pila*
%6 = alloca %struct._Pila*
store %struct._Pila* %0, %struct._Pila** %4
store %struct._Pila* %1, %struct._Pila** %5
store %struct._Pila* %2, %struct._Pila** %6
br label %7
7: ; preds = %34, %3
%8 = load %struct._Pila*, %struct._Pila** %4
%9 = call i32 @pilavacia(%struct._Pila* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load %struct._Pila*, %struct._Pila** %5
%13 = call i32 @pilavacia(%struct._Pila* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br label %16
16: ; preds = %11, %7
%17 = phi i1 [ false, %7 ], [ %15, %11 ]
br i1 %17, label %18, label %35
18: ; preds = %16
%19 = load %struct._Pila*, %struct._Pila** %4
%20 = call i64 @tope(%struct._Pila* %19)
%21 = load %struct._Pila*, %struct._Pila** %5
%22 = call i64 @tope(%struct._Pila* %21)
%23 = icmp slt i64 %20, %22
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load %struct._Pila*, %struct._Pila** %6
%26 = load %struct._Pila*, %struct._Pila** %4
%27 = call i32 @desapilar(%struct._Pila* %26)
%28 = call i32 @apilar(%struct._Pila* %25, i32 %27)
br label %34
29: ; preds = %18
%30 = load %struct._Pila*, %struct._Pila** %6
%31 = load %struct._Pila*, %struct._Pila** %5
%32 = call i32 @desapilar(%struct._Pila* %31)
%33 = call i32 @apilar(%struct._Pila* %30, i32 %32)
br label %34
34: ; preds = %29, %24
br label %7
35: ; preds = %16
%36 = load %struct._Pila*, %struct._Pila** %4
%37 = call i32 @pilavacia(%struct._Pila* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %51, label %39
39: ; preds = %35
br label %40
40: ; preds = %45, %39
%41 = load %struct._Pila*, %struct._Pila** %4
%42 = call i32 @pilavacia(%struct._Pila* %41)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load %struct._Pila*, %struct._Pila** %6
%47 = load %struct._Pila*, %struct._Pila** %4
%48 = call i32 @desapilar(%struct._Pila* %47)
%49 = call i32 @apilar(%struct._Pila* %46, i32 %48)
br label %40
50: ; preds = %40
br label %63
51: ; preds = %35
br label %52
52: ; preds = %57, %51
%53 = load %struct._Pila*, %struct._Pila** %5
%54 = call i32 @pilavacia(%struct._Pila* %53)
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load %struct._Pila*, %struct._Pila** %6
%59 = load %struct._Pila*, %struct._Pila** %5
%60 = call i32 @desapilar(%struct._Pila* %59)
%61 = call i32 @apilar(%struct._Pila* %58, i32 %60)
br label %52
62: ; preds = %52
br label %63
63: ; preds = %62, %50
ret void
}

LLVM IR (-O2):
%struct._Pila = type { i32 }
define void @intercalar(%struct._Pila* %0, %struct._Pila* %1, %struct._Pila* %2) {
%4 = tail call i32 @pilavacia(%struct._Pila* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3, %9
%7 = tail call i32 @pilavacia(%struct._Pila* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = tail call i64 @tope(%struct._Pila* %0)
%11 = tail call i64 @tope(%struct._Pila* %1)
%12 = icmp slt i64 %10, %11
%13 = select i1 %12, %struct._Pila* %0, %struct._Pila* %1
%14 = tail call i32 @desapilar(%struct._Pila* %13)
%15 = tail call i32 @apilar(%struct._Pila* %2, i32 %14)
%16 = tail call i32 @pilavacia(%struct._Pila* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %6, label %18
18: ; preds = %6, %9, %3
%19 = tail call i32 @pilavacia(%struct._Pila* %0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @pilavacia(%struct._Pila* %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %32, label %37
24: ; preds = %18
%25 = tail call i32 @pilavacia(%struct._Pila* %0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24, %27
%28 = tail call i32 @desapilar(%struct._Pila* %0)
%29 = tail call i32 @apilar(%struct._Pila* %2, i32 %28)
%30 = tail call i32 @pilavacia(%struct._Pila* %0)
%31 = icmp eq i32 %30, 0
br i1 %31, label %27, label %37
32: ; preds = %21, %32
%33 = tail call i32 @desapilar(%struct._Pila* %1)
%34 = tail call i32 @apilar(%struct._Pila* %2, i32 %33)
%35 = tail call i32 @pilavacia(%struct._Pila* %1)
%36 = icmp eq i32 %35, 0
br i1 %36, label %32, label %37
37: ; preds = %32, %27, %21, %24
ret void
}