#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*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
FILE *open_file(char *name, int n, char *m) {
  char filename[512];
  FILE *f;
  sprintf(filename, "%s%06d.dat", name, n);
  printf("Abriendo %s\n", filename);
  f = fopen(filename, m);
  if (f == NULL) {
    printf("Error leyendo %s\n", filename);
    return 0;
  } else
    printf("%s OK\n", filename);
  return f;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xea5(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x220(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    11b8 <open_file+0x88>
lea    -0x220(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d6 <open_file+0xa6>
lea    -0x220(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    -0x228(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdx,%r14
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0xeb5(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <sprintf@plt>
lea    0xeae(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xe9b(%rip),%rax
lea    0xea6(%rip),%rdi
cmove  %rax,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s%06d.dat\00"
@.str.1 = [13 x i8] c"Abriendo %s\0A\00"
@.str.2 = [18 x i8] c"Error leyendo %s\0A\00"
@.str.3 = [7 x i8] c"%s OK\0A\00"
define i32* @open_file(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [512 x i8]
%9 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%17 = load i8*, i8** %7
%18 = call i32* @fopen(i8* %16, i8* %17)
store i32* %18, i32** %9
%19 = load i32*, i32** %9
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32* null, i32** %4
br label %29
24: ; preds = %3
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24
%28 = load i32*, i32** %9
store i32* %28, i32** %4
br label %29
29: ; preds = %27, %21
%30 = load i32*, i32** %4
ret i32* %30
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s%06d.dat\00"
@.str.1 = [13 x i8] c"Abriendo %s\0A\00"
@.str.2 = [18 x i8] c"Error leyendo %s\0A\00"
@.str.3 = [7 x i8] c"%s OK\0A\00"
define noalias i32* @open_file(i8* %0, i32 %1, i8* nocapture %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%7 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = call i32* @fopen(i8* %5, i8* %2)
%9 = icmp eq i32* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%11 = call i32 @printf(i8* %10, i8* %5)
ret i32* %8
}