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

/* Variables and functions */
scalar_t__ isEmpty(struct stack *);
int pop(struct stack **);
int /*<<< orphan*/ push(struct stack **, int);
int top(struct stack *);
void sortedInsert(struct stack **s, int x) {
  if (isEmpty(*s) || x > top(*s)) {
    push(s, x);
    return;
  }
  int temp = pop(s);
  sortedInsert(s, x);
  push(s, temp);
}


x86 assembly (clang, -O0):
<sortedInsert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <isEmpty@plt>
cmp    $0x0,%rax
jne    1194 <sortedInsert+0x44>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <top@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jle    11a5 <sortedInsert+0x55>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <push@plt>
jmp    11c9 <sortedInsert+0x79>
mov    -0x8(%rbp),%rdi
call   1030 <pop@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <sortedInsert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <push@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortedInsert>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1050 <isEmpty@plt>
test   %rax,%rax
jne    118a <sortedInsert+0x3a>
mov    (%rbx),%rdi
call   1040 <top@plt>
cmp    %ebp,%eax
jl     118a <sortedInsert+0x3a>
mov    %rbx,%rdi
call   1030 <pop@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <sortedInsert@plt>
mov    %r14d,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <push@plt>

LLVM IR (-O0):
%struct.stack = type { i32 }
define void @sortedInsert(%struct.stack** %0, i32 %1) {
%3 = alloca %struct.stack**
%4 = alloca i32
%5 = alloca i32
store %struct.stack** %0, %struct.stack*** %3
store i32 %1, i32* %4
%6 = load %struct.stack**, %struct.stack*** %3
%7 = load %struct.stack*, %struct.stack** %6
%8 = call i64 @isEmpty(%struct.stack* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load %struct.stack**, %struct.stack*** %3
%13 = load %struct.stack*, %struct.stack** %12
%14 = call i32 @top(%struct.stack* %13)
%15 = icmp sgt i32 %11, %14
br i1 %15, label %16, label %20
16: ; preds = %10, %2
%17 = load %struct.stack**, %struct.stack*** %3
%18 = load i32, i32* %4
%19 = call i32 @push(%struct.stack** %17, i32 %18)
br label %28
20: ; preds = %10
%21 = load %struct.stack**, %struct.stack*** %3
%22 = call i32 @pop(%struct.stack** %21)
store i32 %22, i32* %5
%23 = load %struct.stack**, %struct.stack*** %3
%24 = load i32, i32* %4
%25 = load %struct.stack**, %struct.stack*** %3
%26 = load i32, i32* %5
%27 = call i32 @push(%struct.stack** %25, i32 %26)
br label %28
28: ; preds = %20, %16
ret void
}

LLVM IR (-O2):
%struct.stack = type { i32 }
define void @sortedInsert(%struct.stack** %0, i32 %1) {
%3 = load %struct.stack*, %struct.stack** %0
%4 = tail call i64 @isEmpty(%struct.stack* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load %struct.stack*, %struct.stack** %0
%8 = tail call i32 @top(%struct.stack* %7)
%9 = icmp slt i32 %8, %1
br i1 %9, label %10, label %13
10: ; preds = %2, %6, %13
%11 = phi i32 [ %14, %13 ], [ %1, %6 ], [ %1, %2 ]
%12 = tail call i32 @push(%struct.stack** %0, i32 %11)
ret void
13: ; preds = %6
%14 = tail call i32 @pop(%struct.stack** %0)
tail call void @sortedInsert(%struct.stack** %0, i32 %1)
br label %10
}