#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 */

/* Variables and functions */
int /*<<< orphan*/ __thinthin_dlopen(char *);
int /*<<< orphan*/ __thinthin_syscall(int, int, char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  __thinthin_syscall(1, 1, "hi0\n", 3);
  __thinthin_dlopen("libc.wasm");
  __thinthin_syscall(1, 1, "hi1\n", 3);
  for (;;) {
    puts("hey");
    write(1, "hello world", 5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%esi
lea    0xea5(%rip),%rdx
mov    $0x3,%ecx
mov    %esi,%edi
call   1050 <__thinthin_syscall@plt>
lea    0xe97(%rip),%rdi
call   1060 <__thinthin_dlopen@plt>
mov    $0x1,%esi
lea    0xe90(%rip),%rdx
mov    $0x3,%ecx
mov    %esi,%edi
call   1050 <__thinthin_syscall@plt>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
lea    0xe75(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
jmp    118b <main+0x4b>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdx
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x3,%ecx
call   1050 <__thinthin_syscall@plt>
lea    0xe9f(%rip),%rdi
call   1060 <__thinthin_dlopen@plt>
lea    0xe9d(%rip),%rdx
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x3,%ecx
call   1050 <__thinthin_syscall@plt>
lea    0xe87(%rip),%r14
lea    0xe84(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1040 <write@plt>
jmp    11a0 <main+0x60>

LLVM IR (-O0):
@.str = [5 x i8] c"hi0\0A\00"
@.str.1 = [10 x i8] c"libc.wasm\00"
@.str.2 = [5 x i8] c"hi1\0A\00"
@.str.3 = [4 x i8] c"hey\00"
@.str.4 = [12 x i8] c"hello world\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @__thinthin_syscall(i32 1, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3)
%3 = call i32 @__thinthin_dlopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @__thinthin_syscall(i32 1, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 3)
br label %5
5: ; preds = %5, %0
%6 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @write(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 5)
br label %5
}

LLVM IR (-O2):
@.str = [5 x i8] c"hi0\0A\00"
@.str.1 = [10 x i8] c"libc.wasm\00"
@.str.2 = [5 x i8] c"hi1\0A\00"
@.str.3 = [4 x i8] c"hey\00"
@.str.4 = [12 x i8] c"hello world\00"
define i32 @main() {
%1 = tail call i32 @__thinthin_syscall(i32 1, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3)
%2 = tail call i32 @__thinthin_dlopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @__thinthin_syscall(i32 1, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 3)
br label %4
4: ; preds = %4, %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 5)
br label %4
}