#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*/ sprintf(char *, char *, char *, char *, char *);
int strlen(char *);
char *lock_file_name(char *path, char *s) {
  char *pc;
  for (pc = path + strlen(path); pc != path && *pc != '/'; pc--)
    ;
  if (pc != path)
    pc++;
  sprintf(s, "%s/%s%s", "/var/lock", "LCK..", pc);
  return s;
}


x86 assembly (clang, -O0):
<lock_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     1174 <lock_file_name+0x54>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1184 <lock_file_name+0x64>
jmp    119a <lock_file_name+0x7a>
jmp    1189 <lock_file_name+0x69>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <lock_file_name+0x31>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11b4 <lock_file_name+0x94>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%r8
lea    0xe3d(%rip),%rsi
lea    0xe3e(%rip),%rdx
lea    0xe41(%rip),%rcx
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_file_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
test   %eax,%eax
je     1151 <lock_file_name+0x31>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rax,1),%ecx
cmp    $0x2f,%cl
je     1158 <lock_file_name+0x38>
add    $0xffffffffffffffff,%rax
jne    1140 <lock_file_name+0x20>
jmp    115b <lock_file_name+0x3b>
add    %rax,%rbx
xor    %eax,%eax
jmp    1163 <lock_file_name+0x43>
add    %rax,%rbx
xor    %eax,%eax
cmp    $0x2f,%cl
sete   %al
add    %rax,%rbx
lea    0xe93(%rip),%rsi
lea    0xe94(%rip),%rdx
lea    0xe97(%rip),%rcx
mov    %r14,%rdi
mov    %rbx,%r8
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s/%s%s\00"
@.str.1 = [10 x i8] c"/var/lock\00"
@.str.2 = [6 x i8] c"LCK..\00"
define i8* @lock_file_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8* %10, i8** %5
br label %11
11: ; preds = %23, %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 47
br label %20
20: ; preds = %15, %11
%21 = phi i1 [ false, %11 ], [ %19, %15 ]
br i1 %21, label %22, label %26
22: ; preds = %20
br label %23
23: ; preds = %22
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %5
br label %11
26: ; preds = %20
%27 = load i8*, i8** %5
%28 = load i8*, i8** %3
%29 = icmp ne i8* %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
br label %33
33: ; preds = %30, %26
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s/%s%s\00"
@.str.1 = [10 x i8] c"/var/lock\00"
@.str.2 = [6 x i8] c"LCK..\00"
define i8* @lock_file_name(i8* %0, i8* returned writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = icmp eq i32 %3, 0
br i1 %6, label %17, label %7
7: ; preds = %2, %11
%8 = phi i8* [ %12, %11 ], [ %5, %2 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %8, i64 -1
%13 = icmp eq i8* %12, %0
br i1 %13, label %14, label %7
14: ; preds = %11, %7
%15 = phi i8* [ %8, %7 ], [ %0, %11 ]
%16 = zext i1 %10 to i64
br label %17
17: ; preds = %14, %2
%18 = phi i8* [ %5, %2 ], [ %15, %14 ]
%19 = phi i64 [ 0, %2 ], [ %16, %14 ]
%20 = getelementptr i8, i8* %18, i64 %19
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %20)
ret i8* %1
}