#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int main() {
  FILE *fp;
  char texto[] = "que lindo dia\nai ai";
  int i = 0;
  fp = fopen("texto.txt", "w");
  while (texto[i] != '\ 0')
    fputc(texto[i++], fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb5(%rip),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xea8(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x2030,%eax
je     11b2 <main+0x82>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
mov    -0x30(%rbp,%rax,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    117c <main+0x4c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xee9(%rip),%rdi
lea    0xeec(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
lea    0xebf(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
jmp    1150 <main+0x30>

LLVM IR (-O0):
@__const.main.texto = [20 x i8] c"que lindo dia\0Aai ai\00"
@.str = [10 x i8] c"texto.txt\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [20 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [20 x i8]* %3 to i8*
store i32 0, i32* %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 8240
br i1 %13, label %14, label %22
14: ; preds = %7
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = load i32*, i32** %2
%21 = call i32 @fputc(i8 signext %19, i32* %20)
br label %7
22: ; preds = %7
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
ret i32 0
}

LLVM IR (-O2):
@__const.main.texto = [20 x i8] c"que lindo dia\0Aai ai\00"
@.str = [10 x i8] c"texto.txt\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ %6, %2 ], [ 0, %0 ]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* @__const.main.texto, i64 0, i64 %3
%5 = load i8, i8* %4
%6 = add nuw i64 %3, 1
%7 = tail call i32 @fputc(i8 signext %5, i32* %1)
br label %2
}