#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*/ exit(int);
int /*<<< orphan*/ puts(char *);
void generate_outfile_name(char *input, char *output) {
  int i = 0;
  while (input[i] != '\0') {
    if (i > 128) {
      puts("Error: filename too long");
      exit(1);
    }
    output[i] = input[i];
    i++;
  }
  output[i] = '\0';
  output[i - 2] = 'i';
}


x86 assembly (clang, -O0):
<generate_outfile_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1193 <generate_outfile_name+0x73>
cmpl   $0x80,-0x14(%rbp)
jle    116f <generate_outfile_name+0x4f>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <generate_outfile_name+0x17>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x69,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_outfile_name>:
push   %rax
mov    (%rdi),%cl
xor    %eax,%eax
test   %cl,%cl
je     115b <generate_outfile_name+0x3b>
nopl   0x0(%rax)
mov    %cl,(%rsi,%rax,1)
movzbl 0x1(%rdi,%rax,1),%ecx
test   %cl,%cl
je     1157 <generate_outfile_name+0x37>
cmp    $0x80,%rax
je     116a <generate_outfile_name+0x4a>
mov    %cl,0x1(%rsi,%rax,1)
movzbl 0x2(%rdi,%rax,1),%ecx
add    $0x2,%rax
test   %cl,%cl
jne    1130 <generate_outfile_name+0x10>
jmp    115b <generate_outfile_name+0x3b>
add    $0x1,%rax
mov    %eax,%ecx
movb   $0x0,(%rsi,%rcx,1)
cltq
movb   $0x69,-0x2(%rax,%rsi,1)
pop    %rax
ret
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Error: filename too long\00"
define void @generate_outfile_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %20, %2
%7 = load i8*, i8** %3
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %6
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 128
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %6
32: ; preds = %6
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = sub nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 105, i8* %41
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Error: filename too long\00"
define void @generate_outfile_name(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %2, %18
%6 = phi i64 [ %20, %18 ], [ 0, %2 ]
%7 = phi i8 [ %22, %18 ], [ %3, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %7, i8* %8
%9 = or i64 %6, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %24, label %16
13: ; preds = %16
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %5
%17 = icmp eq i64 %9, 129
br i1 %17, label %13, label %18
18: ; preds = %16
%19 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %11, i8* %19
%20 = add nuw nsw i64 %6, 2
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %18, %5
%25 = phi i64 [ %9, %5 ], [ %20, %18 ]
%26 = trunc i64 %25 to i32
br label %27
27: ; preds = %24, %2
%28 = phi i32 [ 0, %2 ], [ %26, %24 ]
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 0, i8* %30
%31 = add nsw i32 %28, -2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %1, i64 %32
store i8 105, i8* %33
ret void
}