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

/* Variables and functions */
struct kmod_list *kmod_list_last(struct kmod_list *);
struct kmod_list *kmod_list_remove(struct kmod_list *);
struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
                                            unsigned int n) {
  struct kmod_list *l = list;
  unsigned int i;
  for (i = 0; i < n; i++) {
    l = kmod_list_last(l);
    l = kmod_list_remove(l);
  }
  return l;
}


x86 assembly (clang, -O0):
<kmod_list_remove_n_latest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1172 <kmod_list_remove_n_latest+0x52>
mov    -0x18(%rbp),%rdi
call   1030 <kmod_list_last@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <kmod_list_remove@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <kmod_list_remove_n_latest+0x1e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kmod_list_remove_n_latest>:
push   %rbx
mov    %rdi,%rax
test   %esi,%esi
je     1145 <kmod_list_remove_n_latest+0x25>
mov    %esi,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1030 <kmod_list_last@plt>
mov    %rax,%rdi
call   1040 <kmod_list_remove@plt>
add    $0xffffffff,%ebx
jne    1130 <kmod_list_remove_n_latest+0x10>
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.kmod_list = type { i32 }
define %struct.kmod_list* @kmod_list_remove_n_latest(%struct.kmod_list* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %11, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %9, %4 ], [ 0, %2 ]
%6 = phi %struct.kmod_list* [ %8, %4 ], [ %0, %2 ]
%7 = tail call %struct.kmod_list* @kmod_list_last(%struct.kmod_list* %6)
%8 = tail call %struct.kmod_list* @kmod_list_remove(%struct.kmod_list* %7)
%9 = add nuw i32 %5, 1
%10 = icmp eq i32 %9, %1
br i1 %10, label %11, label %4
11: ; preds = %4, %2
%12 = phi %struct.kmod_list* [ %0, %2 ], [ %8, %4 ]
ret %struct.kmod_list* %12
}