#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                           char *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
void vesav_write(char *writeString) {
  static int lineCounter = 0;
  FILE *writeFile;
  writeFile = fopen("/tmp/vesav_debug.txt", "a");
  if (writeFile == NULL) {
    printf("Falha ao iniciar arquivo de debug");
    exit(1);
  }
  if (strlen(writeString) >= 1024) {
    printf("Texto muito grande para ser escrito");
    exit(1);
  }
  fprintf(writeFile, "\n%d - %s", lineCounter++, writeString);
  fclose(writeFile);
}


x86 assembly (clang, -O0):
<vesav_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a4 <vesav_write+0x44>
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x400,%eax
jl     11ce <vesav_write+0x6e>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e7c(%rip),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2e71(%rip)
mov    -0x8(%rbp),%rcx
lea    0xe6f(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vesav_write>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c1 <vesav_write+0x61>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x400,%eax
jge    11ca <vesav_write+0x6a>
mov    0x2ebd(%rip),%edx
lea    0x1(%rdx),%eax
mov    %eax,0x2eb4(%rip)
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rcx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
lea    0xe4f(%rip),%rdi
jmp    11d1 <vesav_write+0x71>
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@vesav_write.lineCounter = internal global i32 0
@.str = [21 x i8] c"/tmp/vesav_debug.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [34 x i8] c"Falha ao iniciar arquivo de debug\00"
@.str.3 = [36 x i8] c"Texto muito grande para ser escrito\00"
@.str.4 = [9 x i8] c"\0A%d - %s\00"
define void @vesav_write(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = icmp sge i32 %12, 1024
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = load i32*, i32** %3
%19 = load i32, i32* @vesav_write.lineCounter
%20 = add nsw i32 %19, 1
store i32 %20, i32* @vesav_write.lineCounter
%21 = load i8*, i8** %2
%22 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %19, i8* %21)
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
ret void
}

LLVM IR (-O2):
@vesav_write.lineCounter = internal unnamed_addr global i32 0
@.str = [21 x i8] c"/tmp/vesav_debug.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [34 x i8] c"Falha ao iniciar arquivo de debug\00"
@.str.3 = [36 x i8] c"Texto muito grande para ser escrito\00"
@.str.4 = [9 x i8] c"\0A%d - %s\00"
define void @vesav_write(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp sgt i32 %8, 1023
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7
%14 = load i32, i32* @vesav_write.lineCounter
%15 = add nsw i32 %14, 1
store i32 %15, i32* @vesav_write.lineCounter
%16 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %14, i8* %0)
%17 = tail call i32 @fclose(i32* %2)
ret void
}