#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*/ printf(char *, ...);
void mostrarProductos(char dir[]) {
  printf("***LISTADO DE PRODUCTOS***\n");
  printf("<codigo> <nombre> <precio> <cantidad>\n");
  FILE *tmp;
  char buffer[512];
  tmp = fopen(dir, "r");
  while (fgets(buffer, 256, tmp) != NULL) {
    printf("%s", buffer);
  }
  fclose(tmp);
}


x86 assembly (clang, -O0):
<mostrarProductos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11b8 <mostrarProductos+0x78>
lea    -0x210(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117f <mostrarProductos+0x3f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mostrarProductos>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rbx
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d2 <mostrarProductos+0x82>
lea    0xe5d(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <mostrarProductos+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"***LISTADO DE PRODUCTOS***\0A\00"
@.str.1 = [39 x i8] c"<codigo> <nombre> <precio> <cantidad>\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
define void @mostrarProductos(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [512 x i8]
store i8* %0, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %3
br label %9
9: ; preds = %14, %1
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32* @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %9
17: ; preds = %9
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
ret void
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [27 x i8] c"***LISTADO DE PRODUCTOS***\00"
@str.4 = [38 x i8] c"<codigo> <nombre> <precio> <cantidad>\00"
define void @mostrarProductos(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.4, i64 0, i64 0))
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1, %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%11 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %9
13: ; preds = %9, %1
%14 = call i32 @fclose(i32* %6)
ret void
}