#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
void introducirProductos(char dir[]) {
  char linea[1024];
  printf("Introduzca los valores del nuevo producto:\n");
  printf("(Formato: <codigo> <nombre> <precio> <cantidad>)\n");
  while (1) {
    fgets(linea, 1024, stdin);
    if (!strcmp(linea, "\n"))
      break;
    FILE *inventario;
    inventario = fopen(dir, "a");
    fputs(linea, inventario);
    fclose(inventario);
  }
}


x86 assembly (clang, -O0):
<introducirProductos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11c2 <introducirProductos+0x62>
jmp    11fd <introducirProductos+0x9d>
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1187 <introducirProductos+0x27>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<introducirProductos>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r15
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e66(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
cmpw   $0xa,(%rsp)
je     11e9 <introducirProductos+0x99>
lea    0xe5f(%rip),%r14
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
cmpw   $0xa,(%rsp)
jne    11b0 <introducirProductos+0x60>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Introduzca los valores del nuevo producto:\0A\00"
@.str.1 = [50 x i8] c"(Formato: <codigo> <nombre> <precio> <cantidad>)\0A\00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c"a\00"
define void @introducirProductos(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %1, %15
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 1024, i32 %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %7
br label %23
15: ; preds = %7
%16 = load i8*, i8** %2
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %17, i32** %4
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32 @fputs(i8* %18, i32* %19)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
br label %7
23: ; preds = %14
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.3 = [2 x i8] c"a\00"
@str = [43 x i8] c"Introduzca los valores del nuevo producto:\00"
@str.4 = [49 x i8] c"(Formato: <codigo> <nombre> <precio> <cantidad>)\00"
define void @introducirProductos(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.4, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 1024, i32 %6)
%8 = bitcast [1024 x i8]* %2 to i16*
%9 = load i16, i16* %8
%10 = icmp eq i16 %9, 10
br i1 %10, label %19, label %11
11: ; preds = %1, %11
%12 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @fputs(i8* %3, i32* %12)
%14 = call i32 @fclose(i32* %12)
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %3, i32 1024, i32 %15)
%17 = load i16, i16* %8
%18 = icmp eq i16 %17, 10
br i1 %18, label %19, label %11
19: ; preds = %11, %1
ret void
}