#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 NAME_MAX;
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *strdup(char *);
char *strrchr(char *, char);
char *get_pkgname(char *exepath) {
  char *filename;
  char pkgname[NAME_MAX];
  filename = strrchr(exepath, '/');
  if (filename == NULL)
    filename = exepath;
  else
    filename = filename + 1;
  snprintf(pkgname, NAME_MAX, "deb.com.samsung.%s", filename);
  return strdup(pkgname);
}


x86 assembly (clang, -O0):
<get_pkgname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <get_pkgname+0x62>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    119e <get_pkgname+0x6e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe4a(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pkgname>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    0x2e94(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %r15,%rcx
lea    0xe89(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strdup@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NAME_MAX = global i32 0
@.str = [19 x i8] c"deb.com.samsung.%s\00"
define i8* @get_pkgname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i32, i32* @NAME_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
%10 = load i8*, i8** %2
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i8*, i8** %2
store i8* %15, i8** %3
br label %19
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %3
br label %19
19: ; preds = %16, %14
%20 = load i32, i32* @NAME_MAX
%21 = load i8*, i8** %3
%22 = call i32 @snprintf(i8* %9, i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i8* @strdup(i8* %9)
%24 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
@NAME_MAX = global i32 0
@.str = [19 x i8] c"deb.com.samsung.%s\00"
define noalias i8* @get_pkgname(i8* %0) {
%2 = load i32, i32* @NAME_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%6 = icmp eq i8* %5, null
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = select i1 %6, i8* %0, i8* %7
%9 = call i32 @snprintf(i8* %4, i32 %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i8* @strdup(i8* %4)
ret i8* %10
}