#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int main(int argc, char **argv) {
  FILE *fp;
  char buffer[100] = "Esto es un texto dentro del fichero.";
  fp = fopen("fichero.txt", "r+");
  fprintf(fp, buffer);
  fprintf(fp, "%s", "\nEsto es otro texto dentro del fichero.");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x64,%edx
call   1050 <memcpy@plt>
lea    0xeef(%rip),%rdi
lea    0xef4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xed4(%rip),%rsi
lea    0xed0(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
movaps 0xf04(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xee8(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xecc(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe94(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe78(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xec9(%rip),%rdi
lea    0xece(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x27,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.buffer = [100 x i8] c"Esto es un texto dentro del fichero.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"fichero.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [40 x i8] c"\0AEsto es otro texto dentro del fichero.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [100 x i8]* %7 to i8*
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* %11)
%13 = load i32*, i32** %6
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buffer = [100 x i8] c"Esto es un texto dentro del fichero.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"fichero.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.3 = [40 x i8] c"\0AEsto es otro texto dentro del fichero.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* %4)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 39, i64 1, i32* %5)
%8 = tail call i32 @fclose(i32* %5)
ret i32 0
}