#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*/ snprintf(char *, int, char *, char *);
char *app_name(char *argv0) {
  char *name, *ptr;
  static char path[256];
  snprintf(path, 256, "%s", argv0);
  for (name = ptr = path; *ptr; ptr++) {
    if (*ptr != '/')
      continue;
    name = ptr + 1;
  }
  return name;
}


x86 assembly (clang, -O0):
<app_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
lea    0x2f19(%rip),%rdi
mov    $0x100,%esi
lea    0xecd(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2f01(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0x2ef6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118d <app_name+0x7d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1170 <app_name+0x60>
jmp    117c <app_name+0x6c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114e <app_name+0x3e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<app_name>:
push   %rbx
mov    %rdi,%rcx
lea    0x2f25(%rip),%rbx
lea    0xede(%rip),%rdx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
lea    0x2f0b(%rip),%rax
jmp    1147 <app_name+0x37>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
add    $0x1,%rax
movzbl -0x1(%rax),%ecx
cmp    $0x2f,%cl
je     1140 <app_name+0x30>
test   %cl,%cl
jne    1143 <app_name+0x33>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@app_name.path = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @app_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @app_name.path, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @app_name.path, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @app_name.path, i64 0, i64 0), i8** %3
br label %7
7: ; preds = %20, %1
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 47
br i1 %15, label %16, label %17
16: ; preds = %11
br label %20
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %3
br label %20
20: ; preds = %17, %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
br label %7
23: ; preds = %7
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@app_name.path = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
define i8* @app_name(i8* %0) {
%2 = tail call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @app_name.path, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %3
3: ; preds = %9, %1
%4 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @app_name.path, i64 0, i64 0), %1 ], [ %10, %9 ]
%5 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @app_name.path, i64 0, i64 0), %1 ], [ %11, %9 ]
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 0, label %12
i8 47, label %7
]
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %9
9: ; preds = %3, %7
%10 = phi i8* [ %8, %7 ], [ %4, %3 ]
%11 = getelementptr inbounds i8, i8* %5, i64 1
br label %3
12: ; preds = %3
ret i8* %4
}