#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*/ debug(char *, char *, ...);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
FILE *open_file(char *name, int number, char *mode) {
  char newname[256];
  register FILE *ans;
  register int i;
  debug("open_file: called with name = %s number = %d", name, number);
  strcpy(newname, name);
  i = strlen(name);
  newname[i++] = ('a' + (number / 26));
  newname[i++] = ('a' + (number % 26));
  newname[i] = '\0';
  debug("open_file: Opening file %s", newname);
  ans = fopen(newname, mode);
  if (ans == NULL) {
    debug("open_file: Cannot open file %s", newname);
  }
  return ans;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <debug@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x12c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%eax
mov    %al,%cl
mov    -0x12c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x12c(%rbp)
cltq
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    %dl,%cl
mov    -0x12c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x12c(%rbp)
cltq
mov    %cl,-0x120(%rbp,%rax,1)
movslq -0x12c(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <debug@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    123c <open_file+0xfc>
lea    -0x120(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <debug@plt>
mov    -0x128(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <debug@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %ebp,%rcx
imul   $0x4ec4ec4f,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x23,%rdx
add    %esi,%edx
lea    0x61(%rdx),%esi
cltq
mov    %sil,(%rsp,%rax,1)
lea    (%rdx,%rdx,4),%esi
lea    (%rsi,%rsi,4),%esi
add    %edx,%esi
sub    %esi,%ecx
add    $0x61,%cl
mov    %cl,0x1(%rsp,%rax,1)
movb   $0x0,0x2(%rsp,%rax,1)
lea    0xe72(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <debug@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e9 <open_file+0xa9>
lea    0xe69(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <debug@plt>
mov    %rbx,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"open_file: called with name = %s number = %d\00"
@.str.1 = [27 x i8] c"open_file: Opening file %s\00"
@.str.2 = [31 x i8] c"open_file: Cannot open file %s\00"
define i32* @open_file(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = call i32 (i8*, i8*, ...) @debug(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %5
%19 = sdiv i32 %18, 26
%20 = add nsw i32 97, %19
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %24
store i8 %21, i8* %25
%26 = load i32, i32* %5
%27 = srem i32 %26, 26
%28 = add nsw i32 97, %27
%29 = trunc i32 %28 to i8
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %32
store i8 %29, i8* %33
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = call i32 (i8*, i8*, ...) @debug(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%40 = load i8*, i8** %6
%41 = call i32* @fopen(i8* %39, i8* %40)
store i32* %41, i32** %8
%42 = load i32*, i32** %8
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %47
44: ; preds = %3
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%46 = call i32 (i8*, i8*, ...) @debug(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %3
%48 = load i32*, i32** %8
ret i32* %48
}

LLVM IR (-O2):
@.str = [45 x i8] c"open_file: called with name = %s number = %d\00"
@.str.1 = [27 x i8] c"open_file: Opening file %s\00"
@.str.2 = [31 x i8] c"open_file: Cannot open file %s\00"
define noalias i32* @open_file(i8* %0, i32 %1, i8* nocapture %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32 (i8*, i8*, ...) @debug(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%7 = call i32 @strcpy(i8* %5, i8* %0)
%8 = call i32 @strlen(i8* %0)
%9 = sdiv i32 %1, 26
%10 = trunc i32 %9 to i8
%11 = add i8 %10, 97
%12 = add nsw i32 %8, 1
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %13
store i8 %11, i8* %14
%15 = srem i32 %1, 26
%16 = trunc i32 %15 to i8
%17 = add nsw i8 %16, 97
%18 = add nsw i32 %8, 2
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %19
store i8 %17, i8* %20
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 (i8*, i8*, ...) @debug(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%24 = call i32* @fopen(i8* %5, i8* %2)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = call i32 (i8*, i8*, ...) @debug(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %28
28: ; preds = %26, %3
ret i32* %24
}