#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*/ uint32_t;
struct slist {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int ntohl(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ slist_begin_riterate(struct slist *);
int /*<<< orphan*/ slist_end_riterate(struct slist *);
scalar_t__ slist_erase(struct slist *, char const *, int /*<<< orphan*/);
int slist_riterate(struct slist *, char const **, int /*<<< orphan*/ *,
                   void **);
void riterate_erase(struct slist *slist) {
  slist_begin_riterate(slist);
  const char *key;
  uint32_t key_len;
  void *value;
  while (slist_riterate(slist, &key, &key_len, &value) != -1) {
    int n = *(const int *)key;
    n = ntohl(n);
    printf("riterate_erase=%d\n", n);
    assert(slist_erase(slist, key, key_len) == 0);
    assert(value == NULL);
  }
  slist_end_riterate(slist);
}


x86 assembly (clang, -O0):
<riterate_erase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <slist_begin_riterate@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1080 <slist_riterate@plt>
cmp    $0xffffffff,%eax
je     11fe <riterate_erase+0x8e>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1090 <ntohl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <slist_erase@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
jmp    1185 <riterate_erase+0x15>
mov    -0x8(%rbp),%rdi
call   1060 <slist_end_riterate@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<riterate_erase>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
call   1030 <slist_begin_riterate@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %rbx,%rdi
call   1080 <slist_riterate@plt>
cmp    $0xffffffff,%eax
je     121c <riterate_erase+0xac>
lea    0xe58(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x18(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax),%edi
call   1090 <ntohl@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1070 <slist_erase@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x18(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1080 <slist_riterate@plt>
cmp    $0xffffffff,%eax
jne    11c0 <riterate_erase+0x50>
mov    %rbx,%rdi
call   1060 <slist_end_riterate@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.slist = type { i32 }
@.str = [19 x i8] c"riterate_erase=%d\0A\00"
define void @riterate_erase(%struct.slist* %0) {
%2 = alloca %struct.slist*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store %struct.slist* %0, %struct.slist** %2
%7 = load %struct.slist*, %struct.slist** %2
%8 = call i32 @slist_begin_riterate(%struct.slist* %7)
br label %9
9: ; preds = %13, %1
%10 = load %struct.slist*, %struct.slist** %2
%11 = call i32 @slist_riterate(%struct.slist* %10, i8** %3, i32* %4, i8** %5)
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i32 @ntohl(i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load %struct.slist*, %struct.slist** %2
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = call i64 @slist_erase(%struct.slist* %21, i8* %22, i32 %23)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i8*, i8** %5
%29 = icmp eq i8* %28, null
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
br label %9
32: ; preds = %9
%33 = load %struct.slist*, %struct.slist** %2
%34 = call i32 @slist_end_riterate(%struct.slist* %33)
ret void
}

LLVM IR (-O2):
%struct.slist = type { i32 }
@.str = [19 x i8] c"riterate_erase=%d\0A\00"
define void @riterate_erase(%struct.slist* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = tail call i32 @slist_begin_riterate(%struct.slist* %0)
%6 = bitcast i8** %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = call i32 @slist_riterate(%struct.slist* %0, i8** %2, i32* %3, i8** %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %30, label %11
11: ; preds = %1
%12 = bitcast i8** %2 to i32**
br label %13
13: ; preds = %11, %13
%14 = load i32*, i32** %12
%15 = load i32, i32* %14
%16 = call i32 @ntohl(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = call i64 @slist_erase(%struct.slist* %0, i8* %18, i32 %19)
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %4
%25 = icmp eq i8* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @slist_riterate(%struct.slist* %0, i8** %2, i32* %3, i8** %4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %13
30: ; preds = %13, %1
%31 = call i32 @slist_end_riterate(%struct.slist* %0)
ret void
}