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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ intlist_append(int /*<<< orphan*/, struct intlist **);
int intlist_extract_min(struct intlist **);
int /*<<< orphan*/ intlist_free(struct intlist **);
int /*<<< orphan*/ intlist_prepend(int /*<<< orphan*/, struct intlist **);
int /*<<< orphan*/ random();
int /*<<< orphan*/ srandom(int);
int main(int argc, char **argv) {
  int n, i;
  struct intlist *l;
  assert(argc == 2);
  n = atoi(argv[1]);
  assert(n > 0);
  srandom(100);
  l = 0;
  for (i = 0; i < n; i++) {
    intlist_prepend(random(), &l);
  }
  intlist_free(&l);
  l = 0;
  for (i = 0; i < n; i++) {
    intlist_append(random(), &l);
  }
  int min = intlist_extract_min(&l);
  for (i = 1; i < n; i++) {
    int m = intlist_extract_min(&l);
    assert(m >= min);
    min = m;
  }
  assert(l == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x64,%edi
call   1030 <srandom@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120d <main+0x8d>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1090 <intlist_prepend@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e1 <main+0x61>
lea    -0x20(%rbp),%rdi
call   1050 <intlist_free@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1251 <main+0xd1>
mov    $0x0,%al
call   1070 <random@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   10a0 <intlist_append@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1225 <main+0xa5>
lea    -0x20(%rbp),%rdi
call   1040 <intlist_extract_min@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a3 <main+0x123>
lea    -0x20(%rbp),%rdi
call   1040 <intlist_extract_min@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1264 <main+0xe4>
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
mov    $0x64,%edi
call   1030 <srandom@plt>
movq   $0x0,(%rsp)
test   %r15d,%r15d
jle    1271 <main+0xf1>
mov    %rsp,%rbp
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1070 <random@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1090 <intlist_prepend@plt>
add    $0xffffffff,%ebx
jne    11e0 <main+0x60>
mov    %rsp,%rdi
call   1050 <intlist_free@plt>
movq   $0x0,(%rsp)
test   %r15d,%r15d
jle    1281 <main+0x101>
mov    %rsp,%rbp
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <random@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   10a0 <intlist_append@plt>
add    $0xffffffff,%ebx
jne    1220 <main+0xa0>
mov    %rsp,%rdi
call   1040 <intlist_extract_min@plt>
cmp    $0x2,%r15d
jl     1289 <main+0x109>
mov    %eax,%ebp
add    $0xffffffff,%r15d
mov    %rsp,%r14
nopl   (%rax)
mov    %r14,%rdi
call   1040 <intlist_extract_min@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    %ebp,%eax
setge  %dil
call   1060 <assert@plt>
mov    %ebx,%ebp
add    $0xffffffff,%r15d
jne    1250 <main+0xd0>
jmp    1289 <main+0x109>
mov    %rsp,%rdi
call   1050 <intlist_free@plt>
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1040 <intlist_extract_min@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.intlist = type { i32 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.intlist*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 @srandom(i32 100)
store %struct.intlist* null, %struct.intlist** %8
store i32 0, i32* %7
br label %24
24: ; preds = %31, %2
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = call i32 (...) @random()
%30 = call i32 @intlist_prepend(i32 %29, %struct.intlist** %8)
br label %31
31: ; preds = %28
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %24
34: ; preds = %24
%35 = call i32 @intlist_free(%struct.intlist** %8)
store %struct.intlist* null, %struct.intlist** %8
store i32 0, i32* %7
br label %36
36: ; preds = %43, %34
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = call i32 (...) @random()
%42 = call i32 @intlist_append(i32 %41, %struct.intlist** %8)
br label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %36
46: ; preds = %36
%47 = call i32 @intlist_extract_min(%struct.intlist** %8)
store i32 %47, i32* %9
store i32 1, i32* %7
br label %48
48: ; preds = %60, %46
%49 = load i32, i32* %7
%50 = load i32, i32* %6
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %63
52: ; preds = %48
%53 = call i32 @intlist_extract_min(%struct.intlist** %8)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = load i32, i32* %9
%56 = icmp sge i32 %54, %55
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i32, i32* %10
store i32 %59, i32* %9
br label %60
60: ; preds = %52
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %48
63: ; preds = %48
%64 = load %struct.intlist*, %struct.intlist** %8
%65 = icmp eq %struct.intlist* %64, null
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
ret i32 0
}

LLVM IR (-O2):
%struct.intlist = type { i32 }
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.intlist*
%4 = bitcast %struct.intlist** %3 to i8*
%5 = icmp eq i32 %0, 2
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @srandom(i32 100)
store %struct.intlist* null, %struct.intlist** %3
br i1 %11, label %17, label %15
15: ; preds = %2
%16 = call i32 @intlist_free(%struct.intlist** %3)
store %struct.intlist* null, %struct.intlist** %3
br label %31
17: ; preds = %2, %17
%18 = phi i32 [ %21, %17 ], [ 0, %2 ]
%19 = call i32 (...) @random()
%20 = call i32 @intlist_prepend(i32 %19, %struct.intlist** %3)
%21 = add nuw nsw i32 %18, 1
%22 = icmp eq i32 %21, %10
br i1 %22, label %23, label %17
23: ; preds = %17
%24 = call i32 @intlist_free(%struct.intlist** %3)
store %struct.intlist* null, %struct.intlist** %3
br i1 %11, label %25, label %31
25: ; preds = %23, %25
%26 = phi i32 [ %29, %25 ], [ 0, %23 ]
%27 = call i32 (...) @random()
%28 = call i32 @intlist_append(i32 %27, %struct.intlist** %3)
%29 = add nuw nsw i32 %26, 1
%30 = icmp eq i32 %29, %10
br i1 %30, label %33, label %25
31: ; preds = %15, %23
%32 = call i32 @intlist_extract_min(%struct.intlist** %3)
br label %45
33: ; preds = %25
%34 = call i32 @intlist_extract_min(%struct.intlist** %3)
%35 = icmp sgt i32 %10, 1
br i1 %35, label %36, label %45
36: ; preds = %33, %36
%37 = phi i32 [ %43, %36 ], [ 1, %33 ]
%38 = phi i32 [ %39, %36 ], [ %34, %33 ]
%39 = call i32 @intlist_extract_min(%struct.intlist** %3)
%40 = icmp sge i32 %39, %38
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = add nuw nsw i32 %37, 1
%44 = icmp eq i32 %43, %10
br i1 %44, label %45, label %36
45: ; preds = %36, %31, %33
%46 = load %struct.intlist*, %struct.intlist** %3
%47 = icmp eq %struct.intlist* %46, null
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
ret i32 0
}