#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 */
size_t strnlen(char *, int);
char *strnstr(char *, char *, int);
char *make_infilename(char *infile) {
  size_t infilelen;
  char *r, *ret;
  if (infile == NULL) {
    return NULL;
  }
  infilelen = strnlen(infile, (1048576));
  if (infilelen >= (1048576)) {
    return NULL;
  }
  ret = infile;
  r = infile;
  while ((r = strnstr(r, "/", infilelen + r - infile)) != NULL) {
    r = r + (1);
    ret = r;
  }
  return ret;
}


x86 assembly (clang, -O0):
<make_infilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <make_infilename+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <make_infilename+0xb1>
mov    -0x10(%rbp),%rdi
mov    $0x100000,%esi
call   1030 <strnlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x100000,-0x18(%rbp)
jb     1171 <make_infilename+0x51>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <make_infilename+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0xe63(%rip),%rsi
call   1040 <strnstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c9 <make_infilename+0xa9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1181 <make_infilename+0x61>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_infilename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1142 <make_infilename+0x22>
mov    %rdi,%r14
mov    $0x100000,%esi
call   1030 <strnlen@plt>
cmp    $0xfffff,%rax
jbe    1146 <make_infilename+0x26>
xor    %ebx,%ebx
jmp    117e <make_infilename+0x5e>
mov    %rax,%r15
lea    0xeb0(%rip),%r12
mov    %r14,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,%rbx
lea    (%rcx,%r15,1),%edx
sub    %r14d,%edx
mov    %rcx,%rdi
mov    %r12,%rsi
call   1040 <strnstr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
jne    1160 <make_infilename+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @make_infilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %37
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @strnlen(i8* %11, i32 1048576)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp uge i64 %13, 1048576
br i1 %14, label %15, label %16
15: ; preds = %10
store i8* null, i8** %2
br label %37
16: ; preds = %10
%17 = load i8*, i8** %3
store i8* %17, i8** %6
%18 = load i8*, i8** %3
store i8* %18, i8** %5
br label %19
19: ; preds = %31, %16
%20 = load i8*, i8** %5
%21 = load i64, i64* %4
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 %21
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @strnstr(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %28)
store i8* %29, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %19
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8* %33, i8** %5
%34 = load i8*, i8** %5
store i8* %34, i8** %6
br label %19
35: ; preds = %19
%36 = load i8*, i8** %6
store i8* %36, i8** %2
br label %37
37: ; preds = %35, %15, %9
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @make_infilename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i64 @strnlen(i8* %0, i32 1048576)
%5 = icmp ugt i64 %4, 1048575
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = ptrtoint i8* %0 to i64
br label %8
8: ; preds = %8, %6
%9 = phi i8* [ %16, %8 ], [ %0, %6 ]
%10 = getelementptr inbounds i8, i8* %9, i64 %4
%11 = ptrtoint i8* %10 to i64
%12 = sub i64 %11, %7
%13 = trunc i64 %12 to i32
%14 = tail call i8* @strnstr(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i8* %14, null
%16 = getelementptr inbounds i8, i8* %14, i64 1
br i1 %15, label %17, label %8
17: ; preds = %8, %3, %1
%18 = phi i8* [ null, %1 ], [ null, %3 ], [ %9, %8 ]
ret i8* %18
}