#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 */
typedef int /*<<< orphan*/ MENU;
typedef int /*<<< orphan*/ ITEM;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ **);
int /*<<< orphan*/ free_item(int /*<<< orphan*/ *);
int /*<<< orphan*/ free_menu(int /*<<< orphan*/ *);
int /*<<< orphan*/ unpost_menu(int /*<<< orphan*/ *);
void clear_menu(MENU *my_menu, ITEM **my_items) {
  unpost_menu(my_menu);
  free_menu(my_menu);
  for (int i = 0; my_items[i]; ++i)
    free_item(my_items[i]);
  free(my_items);
}


x86 assembly (clang, -O0):
<clear_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <unpost_menu@plt>
mov    -0x8(%rbp),%rdi
call   1060 <free_menu@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     119b <clear_menu+0x5b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <free_item@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <clear_menu+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_menu>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <unpost_menu@plt>
mov    %rbx,%rdi
call   1060 <free_menu@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
je     1181 <clear_menu+0x41>
lea    0x8(%r14),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1050 <free_item@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1170 <clear_menu+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @clear_menu(i32* %0, i32** %1) {
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i32
store i32* %0, i32** %3
store i32** %1, i32*** %4
%6 = load i32*, i32** %3
%7 = call i32 @unpost_menu(i32* %6)
%8 = load i32*, i32** %3
%9 = call i32 @free_menu(i32* %8)
store i32 0, i32* %5
br label %10
10: ; preds = %24, %2
%11 = load i32**, i32*** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32*, i32** %11, i64 %13
%15 = load i32*, i32** %14
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %27
17: ; preds = %10
%18 = load i32**, i32*** %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32*, i32** %18, i64 %20
%22 = load i32*, i32** %21
%23 = call i32 @free_item(i32* %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %10
27: ; preds = %10
%28 = load i32**, i32*** %4
%29 = call i32 @free(i32** %28)
ret void
}

LLVM IR (-O2):
define void @clear_menu(i32* %0, i32** nocapture %1) {
%3 = tail call i32 @unpost_menu(i32* %0)
%4 = tail call i32 @free_menu(i32* %0)
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %9, %2
%8 = tail call i32 @free(i32** %1)
ret void
9: ; preds = %2, %9
%10 = phi i64 [ %13, %9 ], [ 0, %2 ]
%11 = phi i32* [ %15, %9 ], [ %5, %2 ]
%12 = tail call i32 @free_item(i32* %11)
%13 = add nuw i64 %10, 1
%14 = getelementptr inbounds i32*, i32** %1, i64 %13
%15 = load i32*, i32** %14
%16 = icmp eq i32* %15, null
br i1 %16, label %7, label %9
}