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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
struct list *init();
int /*<<< orphan*/ kill(struct list *);
char *pop(struct list *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(struct list *, char *);
int main(void) {
  struct list *list = init();
  push(list, "123");
  push(list, "456");
  push(list, "789");
  char *string;
  printf("LIFO:\n");
  while ((string = pop(list, 1)) != NULL) {
    printf("Last element in the list: %s\n", string);
    free(string);
  }
  push(list, "foo");
  push(list, "bar");
  push(list, "test123");
  push(list, "test456");
  printf("FIFO:\n");
  while ((string = pop(list, 0)) != NULL) {
    printf("Last element in the list: %s\n", string);
    free(string);
  }
  push(list, "test");
  push(list, "123");
  while ((string = pop(list, 1)) != NULL) {
    printf("Last element in the list: %s\n", string);
    free(string);
  }
  kill(list);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <init@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <push@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <pop@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f4 <main+0x94>
mov    -0x18(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11b8 <main+0x58>
mov    -0x10(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1080 <push@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <pop@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     127b <main+0x11b>
mov    -0x18(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1242 <main+0xe2>
mov    -0x10(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1080 <push@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <pop@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12d7 <main+0x177>
mov    -0x18(%rbp),%rsi
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    129b <main+0x13b>
mov    -0x10(%rbp),%rdi
call   1070 <kill@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <init@plt>
mov    %rax,%r15
lea    0xea8(%rip),%rsi
mov    %rax,%rdi
call   1090 <push@plt>
lea    0xea1(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xe5c(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <pop@plt>
test   %rax,%rax
je     120a <main+0x9a>
mov    %rax,%rbx
lea    0xe30(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <pop@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e0 <main+0x70>
lea    0xe11(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xe06(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xdfb(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xdf4(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <pop@plt>
test   %rax,%rax
je     1297 <main+0x127>
mov    %rax,%rbx
lea    0xd99(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <pop@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1270 <main+0x100>
lea    0xd9c(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
lea    0xd81(%rip),%rsi
mov    %r15,%rdi
call   1090 <push@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <pop@plt>
test   %rax,%rax
je     130a <main+0x19a>
mov    %rax,%rbx
lea    0xd33(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <pop@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12e0 <main+0x170>
mov    %r15,%rdi
call   1080 <kill@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.list = type { i32 }
@.str = [4 x i8] c"123\00"
@.str.1 = [4 x i8] c"456\00"
@.str.2 = [4 x i8] c"789\00"
@.str.3 = [7 x i8] c"LIFO:\0A\00"
@.str.4 = [30 x i8] c"Last element in the list: %s\0A\00"
@.str.5 = [4 x i8] c"foo\00"
@.str.6 = [4 x i8] c"bar\00"
@.str.7 = [8 x i8] c"test123\00"
@.str.8 = [8 x i8] c"test456\00"
@.str.9 = [7 x i8] c"FIFO:\0A\00"
@.str.10 = [5 x i8] c"test\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.list*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call %struct.list* (...) @init()
store %struct.list* %4, %struct.list** %2
%5 = load %struct.list*, %struct.list** %2
%6 = call i32 @push(%struct.list* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = load %struct.list*, %struct.list** %2
%8 = call i32 @push(%struct.list* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = load %struct.list*, %struct.list** %2
%10 = call i32 @push(%struct.list* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %16, %0
%13 = load %struct.list*, %struct.list** %2
%14 = call i8* @pop(%struct.list* %13, i32 1)
store i8* %14, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
br label %12
21: ; preds = %12
%22 = load %struct.list*, %struct.list** %2
%23 = call i32 @push(%struct.list* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%24 = load %struct.list*, %struct.list** %2
%25 = call i32 @push(%struct.list* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%26 = load %struct.list*, %struct.list** %2
%27 = call i32 @push(%struct.list* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%28 = load %struct.list*, %struct.list** %2
%29 = call i32 @push(%struct.list* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %31
31: ; preds = %35, %21
%32 = load %struct.list*, %struct.list** %2
%33 = call i8* @pop(%struct.list* %32, i32 0)
store i8* %33, i8** %3
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8*, i8** %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %3
%39 = call i32 @free(i8* %38)
br label %31
40: ; preds = %31
%41 = load %struct.list*, %struct.list** %2
%42 = call i32 @push(%struct.list* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%43 = load %struct.list*, %struct.list** %2
%44 = call i32 @push(%struct.list* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %49, %40
%46 = load %struct.list*, %struct.list** %2
%47 = call i8* @pop(%struct.list* %46, i32 1)
store i8* %47, i8** %3
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i8*, i8** %3
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %3
%53 = call i32 @free(i8* %52)
br label %45
54: ; preds = %45
%55 = load %struct.list*, %struct.list** %2
%56 = call i32 @kill(%struct.list* %55)
ret i32 0
}

LLVM IR (-O2):
%struct.list = type { i32 }
@.str = [4 x i8] c"123\00"
@.str.1 = [4 x i8] c"456\00"
@.str.2 = [4 x i8] c"789\00"
@.str.4 = [30 x i8] c"Last element in the list: %s\0A\00"
@.str.5 = [4 x i8] c"foo\00"
@.str.6 = [4 x i8] c"bar\00"
@.str.7 = [8 x i8] c"test123\00"
@.str.8 = [8 x i8] c"test456\00"
@.str.10 = [5 x i8] c"test\00"
@str = [6 x i8] c"LIFO:\00"
@str.11 = [6 x i8] c"FIFO:\00"
define i32 @main() {
%1 = tail call %struct.list* (...) @init()
%2 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%6 = tail call i8* @pop(%struct.list* %1, i32 1)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %0, %8
%9 = phi i8* [ %12, %8 ], [ %6, %0 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%11 = tail call i32 @free(i8* %9)
%12 = tail call i8* @pop(%struct.list* %1, i32 1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %8
14: ; preds = %8, %0
%15 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%17 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%18 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.11, i64 0, i64 0))
%20 = tail call i8* @pop(%struct.list* %1, i32 0)
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %14, %22
%23 = phi i8* [ %26, %22 ], [ %20, %14 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = tail call i32 @free(i8* %23)
%26 = tail call i8* @pop(%struct.list* %1, i32 0)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %22
28: ; preds = %22, %14
%29 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%30 = tail call i32 @push(%struct.list* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%31 = tail call i8* @pop(%struct.list* %1, i32 1)
%32 = icmp eq i8* %31, null
br i1 %32, label %39, label %33
33: ; preds = %28, %33
%34 = phi i8* [ %37, %33 ], [ %31, %28 ]
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = tail call i32 @free(i8* %34)
%37 = tail call i8* @pop(%struct.list* %1, i32 1)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %33
39: ; preds = %33, %28
%40 = tail call i32 @kill(%struct.list* %1)
ret i32 0
}