#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 fs_close(int);
int fs_create(char *);
int fs_open(char *);
int fs_read(int, char *, int);
int fs_write(int, char *, int);
int make_fs(char *);
scalar_t__ malloc(int);
int mount_fs(char *);
int /*<<< orphan*/ printf(char *, ...);
int umount_fs(char *);
int main() {
  printf("make:  %d\n", make_fs("test_disk.fs"));
  printf("mount: %d\n", mount_fs("test_disk.fs"));
  printf("fs_create: %d\n", fs_create("salam.txt"));
  int filedes = fs_open("salam.txt");
  printf("fs_open:   %d\n", filedes);
  printf("fs_write:  %d\n", fs_write(filedes, "Salam Chetori???", 17));
  char *buffer = (char *)malloc(200);
  printf("fs_read:   %d\n", fs_read(filedes, buffer, 200));
  printf("read: %s\n", buffer);
  printf("fs_close:  %d\n", fs_close(filedes));
  printf("umount:%d\n", umount_fs("test_disk.fs"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe55(%rip),%rdi
call   1030 <make_fs@plt>
mov    %eax,%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe39(%rip),%rdi
call   10c0 <mount_fs@plt>
mov    %eax,%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe44(%rip),%rdi
call   1050 <fs_create@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe28(%rip),%rdi
call   1040 <fs_open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe2d(%rip),%rsi
mov    $0x11,%edx
call   10b0 <fs_write@plt>
mov    %eax,%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xc8,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0xc8,%edx
call   1070 <fs_read@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <fs_close@plt>
mov    %eax,%esi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd64(%rip),%rdi
call   1090 <umount_fs@plt>
mov    %eax,%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe60(%rip),%r14
mov    %r14,%rdi
call   1030 <make_fs@plt>
lea    0xe46(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   10c0 <mount_fs@plt>
lea    0xe46(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe50(%rip),%rbp
mov    %rbp,%rdi
call   1050 <fs_create@plt>
lea    0xe32(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1040 <fs_open@plt>
mov    %eax,%ebp
lea    0xe31(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe3f(%rip),%rsi
mov    %ebp,%edi
mov    $0x11,%edx
call   10b0 <fs_write@plt>
lea    0xe1d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xc8,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0xc8,%edx
call   1070 <fs_read@plt>
lea    0xe11(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe10(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <fs_close@plt>
lea    0xe02(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1090 <umount_fs@plt>
lea    0xdf9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"make: %d\0A\00"
@.str.1 = [13 x i8] c"test_disk.fs\00"
@.str.2 = [11 x i8] c"mount: %d\0A\00"
@.str.3 = [15 x i8] c"fs_create: %d\0A\00"
@.str.4 = [10 x i8] c"salam.txt\00"
@.str.5 = [15 x i8] c"fs_open: %d\0A\00"
@.str.6 = [15 x i8] c"fs_write: %d\0A\00"
@.str.7 = [17 x i8] c"Salam Chetori???\00"
@.str.8 = [15 x i8] c"fs_read: %d\0A\00"
@.str.9 = [10 x i8] c"read: %s\0A\00"
@.str.10 = [15 x i8] c"fs_close: %d\0A\00"
@.str.11 = [11 x i8] c"umount:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 @make_fs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @mount_fs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = call i32 @fs_create(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = call i32 @fs_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @fs_write(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 17)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %14)
%16 = call i64 @malloc(i32 200)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
%18 = load i32, i32* %2
%19 = load i8*, i8** %3
%20 = call i32 @fs_read(i32 %18, i8* %19, i32 200)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %2
%25 = call i32 @fs_close(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %25)
%27 = call i32 @umount_fs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"make: %d\0A\00"
@.str.1 = [13 x i8] c"test_disk.fs\00"
@.str.2 = [11 x i8] c"mount: %d\0A\00"
@.str.3 = [15 x i8] c"fs_create: %d\0A\00"
@.str.4 = [10 x i8] c"salam.txt\00"
@.str.5 = [15 x i8] c"fs_open: %d\0A\00"
@.str.6 = [15 x i8] c"fs_write: %d\0A\00"
@.str.7 = [17 x i8] c"Salam Chetori???\00"
@.str.8 = [15 x i8] c"fs_read: %d\0A\00"
@.str.9 = [10 x i8] c"read: %s\0A\00"
@.str.10 = [15 x i8] c"fs_close: %d\0A\00"
@.str.11 = [11 x i8] c"umount:%d\0A\00"
define i32 @main() {
%1 = tail call i32 @make_fs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @mount_fs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = tail call i32 @fs_create(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = tail call i32 @fs_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %7)
%9 = tail call i32 @fs_write(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 17)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %9)
%11 = tail call i64 @malloc(i32 200)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @fs_read(i32 %7, i8* %12, i32 200)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %12)
%16 = tail call i32 @fs_close(i32 %7)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 %16)
%18 = tail call i32 @umount_fs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 %18)
ret i32 0
}