#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 PATH_MAX;
int /*<<< orphan*/ elg_cntl_msg(char *, char *);
int /*<<< orphan*/ elg_error_msg(char *, char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void epk_archive_commit(char *filename) {
  int mark = strlen(filename) - 1;
  char tmp_name[PATH_MAX];
  if (filename[mark] != '+') {
    elg_error_msg("Can't commit archive file with name %s", filename);
  }
  strcpy(tmp_name, filename);
  tmp_name[mark] = '\0';
  if (rename(filename, tmp_name) != 0) {
    elg_error_msg("Abort: commit/rename archive file %s", filename);
  } else {
    elg_cntl_msg("Committed archive file %s", filename);
  }
  filename[mark] = '\0';
}


x86 assembly (clang, -O0):
<epk_archive_commit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e7e(%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),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
je     11bc <epk_archive_commit+0x6c>
mov    -0x8(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1060 <elg_error_msg@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rsi
movslq -0xc(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x8(%rbp),%rdi
call   1070 <rename@plt>
cmp    $0x0,%rax
je     11fd <epk_archive_commit+0xad>
mov    -0x8(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1060 <elg_error_msg@plt>
jmp    120d <epk_archive_commit+0xbd>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1040 <elg_cntl_msg@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epk_archive_commit>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
movslq %eax,%r15
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmpb   $0x2b,-0x1(%r15,%r14,1)
je     1196 <epk_archive_commit+0x46>
lea    0xe72(%rip),%rdi
mov    %r14,%rsi
call   1060 <elg_error_msg@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movb   $0x0,-0x1(%rbx,%r15,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
test   %rax,%rax
je     11c8 <epk_archive_commit+0x78>
lea    0xe69(%rip),%rdi
mov    %r14,%rsi
call   1060 <elg_error_msg@plt>
jmp    11d7 <epk_archive_commit+0x87>
lea    0xe7d(%rip),%rdi
mov    %r14,%rsi
call   1040 <elg_cntl_msg@plt>
movb   $0x0,-0x1(%r14,%r15,1)
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [39 x i8] c"Can't commit archive file with name %s\00"
@.str.1 = [37 x i8] c"Abort: commit/rename archive file %s\00"
@.str.2 = [26 x i8] c"Committed archive file %s\00"
define void @epk_archive_commit(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 43
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = call i32 @elg_error_msg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %1
%24 = load i8*, i8** %2
%25 = call i32 @strcpy(i8* %12, i8* %24)
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %12, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %2
%30 = call i64 @rename(i8* %29, i8* %12)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i8*, i8** %2
%34 = call i32 @elg_error_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %38
35: ; preds = %23
%36 = load i8*, i8** %2
%37 = call i32 @elg_cntl_msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %32
%39 = load i8*, i8** %2
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [39 x i8] c"Can't commit archive file with name %s\00"
@.str.1 = [37 x i8] c"Abort: commit/rename archive file %s\00"
@.str.2 = [26 x i8] c"Committed archive file %s\00"
define void @epk_archive_commit(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 43
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = tail call i32 @elg_error_msg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %1
%14 = call i32 @strcpy(i8* %6, i8* %0)
%15 = getelementptr inbounds i8, i8* %6, i64 %7
store i8 0, i8* %15
%16 = call i64 @rename(i8* %0, i8* %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @elg_error_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
20: ; preds = %13
%21 = call i32 @elg_cntl_msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %20, %18
store i8 0, i8* %8
ret void
}