#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ mymalloc(scalar_t__, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
char *genlockfilename(char *in) {
  char *dummy =
      (char *)mymalloc(strlen(in) + strlen(".lock") + 1, "lock filename");
  if (!dummy) {
    fprintf(stderr, "genlockfilename::malloc: failure");
    return NULL;
  }
  sprintf(dummy, "%s.lock", in);
  return dummy;
}


x86 assembly (clang, -O0):
<genlockfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    0xed1(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
lea    0xe89(%rip),%rsi
call   1050 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ad <genlockfilename+0x6d>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c9 <genlockfilename+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genlockfilename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x6(%rax),%rdi
lea    0xea9(%rip),%rsi
call   1050 <mymalloc@plt>
test   %rax,%rax
je     1178 <genlockfilename+0x38>
mov    %rax,%rbx
lea    0xec4(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
jmp    118f <genlockfilename+0x4f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c".lock\00"
@.str.1 = [14 x i8] c"lock filename\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"genlockfilename::malloc: failure\00"
@.str.3 = [8 x i8] c"%s.lock\00"
define i8* @genlockfilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strlen(i8* %5)
%7 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = add nsw i64 %6, %7
%9 = add nsw i64 %8, 1
%10 = call i64 @mymalloc(i64 %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %22
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %4
store i8* %21, i8** %2
br label %22
22: ; preds = %17, %14
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"lock filename\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"genlockfilename::malloc: failure\00"
@.str.3 = [8 x i8] c"%s.lock\00"
define i8* @genlockfilename(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 6
%4 = tail call i64 @mymalloc(i64 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %12
10: ; preds = %1
%11 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %7
%13 = phi i8* [ %5, %10 ], [ null, %7 ]
ret i8* %13
}