#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 fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void fagreg_dat(char dir[], int N) {
  FILE *arc;
  if ((arc = fopen(dir, "a+b")) == NULL) {
    printf("NO se pudo abrir el archivo para agregar el dato.");
    exit(1);
  }
  if (fwrite(&N, sizeof(int), 1, arc) != 1)
    printf("NO se pudo escribir el dato.");
  fclose(arc);
}


x86 assembly (clang, -O0):
<fagreg_dat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1193 <fagreg_dat+0x43>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     11bf <fagreg_dat+0x6f>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fagreg_dat>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,0xc(%rsp)
lea    0xea0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a2 <fagreg_dat+0x52>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     1195 <fagreg_dat+0x45>
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <fclose@plt>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"a+b\00"
@.str.1 = [50 x i8] c"NO se pudo abrir el archivo para agregar el dato.\00"
@.str.2 = [29 x i8] c"NO se pudo escribir el dato.\00"
define void @fagreg_dat(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i32*, i32** %5
%14 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %13)
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"a+b\00"
@.str.1 = [50 x i8] c"NO se pudo abrir el archivo para agregar el dato.\00"
@.str.2 = [29 x i8] c"NO se pudo escribir el dato.\00"
define void @fagreg_dat(i8* nocapture %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i32 @fclose(i32* %4)
ret void
}