#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 */

/* Variables and functions */
int /*<<< orphan*/ fatalError(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void create_filename(int rank, int file_no, const char *bname, char *fname) {
  const char totext[] = "0123456789";
  char buffer[6];
  if (rank > 99999) {
    fatalError("rank is too large for ERIFS");
  }
  if (file_no > 99999) {
    fatalError("file number is too large for ERIFS");
  }
  strncpy(fname, "/glade/scratch/pnichols/", 25);
  sprintf(buffer, "%d", rank);
  strncat(fname, buffer, 6);
  sprintf(buffer, "%d", file_no);
  strncat(fname, buffer, 6);
  strncat(fname, bname, strlen(bname) + 1);
}


x86 assembly (clang, -O0):
<create_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x23(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x19(%rbp)
cmpl   $0x1869f,-0x4(%rbp)
jle    119e <create_filename+0x4e>
lea    0xe72(%rip),%rdi
call   1060 <fatalError@plt>
cmpl   $0x1869f,-0x8(%rbp)
jle    11b7 <create_filename+0x67>
lea    0xe75(%rip),%rdi
call   1060 <fatalError@plt>
mov    -0x18(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x19,%edx
call   1030 <strncpy@plt>
lea    -0x29(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe89(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    $0x6,%edx
call   1050 <strncat@plt>
lea    -0x29(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe64(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    $0x6,%edx
call   1050 <strncat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1050 <strncat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%r13d
cmp    $0x186a0,%edi
jl     117b <create_filename+0x2b>
lea    0xe8a(%rip),%rdi
call   1060 <fatalError@plt>
cmp    $0x186a0,%r15d
jl     1190 <create_filename+0x40>
lea    0xe91(%rip),%rdi
call   1060 <fatalError@plt>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
mov    $0x19,%edx
call   1030 <strncpy@plt>
lea    0xead(%rip),%r12
lea    0x2(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1050 <strncat@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strncat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.create_filename.totext = [11 x i8] c"0123456789\00"
@.str = [28 x i8] c"rank is too large for ERIFS\00"
@.str.1 = [35 x i8] c"file number is too large for ERIFS\00"
@.str.2 = [25 x i8] c"/glade/scratch/pnichols/\00"
@.str.3 = [3 x i8] c"%d\00"
define void @create_filename(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [11 x i8]
%10 = alloca [6 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = bitcast [11 x i8]* %9 to i8*
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 99999
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 @fatalError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %4
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 99999
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @fatalError(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = load i8*, i8** %8
%23 = call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 25)
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %8
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%29 = call i32 @strncat(i8* %27, i8* %28, i32 6)
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%31 = load i32, i32* %6
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %8
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%35 = call i32 @strncat(i8* %33, i8* %34, i32 6)
%36 = load i8*, i8** %8
%37 = load i8*, i8** %7
%38 = load i8*, i8** %7
%39 = call i32 @strlen(i8* %38)
%40 = add nsw i32 %39, 1
%41 = call i32 @strncat(i8* %36, i8* %37, i32 %40)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"rank is too large for ERIFS\00"
@.str.1 = [35 x i8] c"file number is too large for ERIFS\00"
@.str.2 = [25 x i8] c"/glade/scratch/pnichols/\00"
@.str.3 = [3 x i8] c"%d\00"
define void @create_filename(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [6 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%7 = icmp sgt i32 %0, 99999
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @fatalError(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = icmp sgt i32 %1, 99999
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @fatalError(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = tail call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 25)
%16 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%17 = call i32 @strncat(i8* %3, i8* %6, i32 6)
%18 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%19 = call i32 @strncat(i8* %3, i8* %6, i32 6)
%20 = call i32 @strlen(i8* %2)
%21 = add nsw i32 %20, 1
%22 = call i32 @strncat(i8* %3, i8* %2, i32 %21)
ret void
}