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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void saveLayout(char *layout_c) {
  FILE *l_file = fopen("bus.txt", "w");
  int r = fputs(layout_c, l_file);
  if (r == EOF) {
    printf("Error! File was not written.\n");
  } else {
    printf("File was written successfully!\n");
  }
  fclose(l_file);
  printf("Thanks for using this program\n");
  printf("EAP / exercise 2 / theme 1\n");
}


x86 assembly (clang, -O0):
<saveLayout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <saveLayout+0x56>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
jmp    11a2 <saveLayout+0x62>
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveLayout>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%eax
lea    0xeea(%rip),%rax
lea    0xe8b(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"bus.txt\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.2 = [30 x i8] c"Error! File was not written.\0A\00"
@.str.3 = [32 x i8] c"File was written successfully!\0A\00"
@.str.4 = [31 x i8] c"Thanks for using this program\0A\00"
@.str.5 = [28 x i8] c"EAP / exercise 2 / theme 1\0A\00"
define void @saveLayout(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i8*, i8** %2
%7 = load i32*, i32** %3
%8 = call i32 @fputs(i8* %6, i32* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"bus.txt\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [31 x i8] c"File was written successfully!\00"
@str.6 = [30 x i8] c"Thanks for using this program\00"
@str.7 = [27 x i8] c"EAP / exercise 2 / theme 1\00"
@str.8 = [29 x i8] c"Error! File was not written.\00"
define void @saveLayout(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @fputs(i8* %0, i32* %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
%6 = select i1 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0)
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
%8 = tail call i32 @fclose(i32* %2)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
ret void
}