#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*/ free(char *);
char *malloc(int);
int snprintf(char *, int, char *, char *, char *);
int strlen(char *);
char *lxclock_name(char *container) {
  int ret;
  int len = strlen(container) + strlen("/lxcapi.") + 1;
  char *dest = malloc(len);
  if (!dest)
    return NULL;
  ret = snprintf(dest, len, "%s%s", "/lxcapi.", container);
  if (ret < 0 || ret >= len) {
    free(dest);
    return NULL;
  }
  return dest;
}


x86 assembly (clang, -O0):
<lxclock_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    0xea1(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1195 <lxclock_name+0x55>
movq   $0x0,-0x8(%rbp)
jmp    11ea <lxclock_name+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%r8
lea    0xe62(%rip),%rdx
lea    0xe52(%rip),%rcx
call   1050 <snprintf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11cc <lxclock_name+0x8c>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     11e2 <lxclock_name+0xa2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <lxclock_name+0xaa>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lxclock_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xea6(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r14,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a7 <lxclock_name+0x67>
mov    %rax,%rbx
lea    0xe8a(%rip),%rdx
lea    0xe7a(%rip),%rcx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%r8
call   1050 <snprintf@plt>
test   %eax,%eax
js     119f <lxclock_name+0x5f>
add    %r14d,%r12d
cmp    %r12d,%eax
jle    11a9 <lxclock_name+0x69>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/lxcapi.\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @lxclock_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = add nsw i32 %8, %9
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
store i8* null, i8** %2
br label %33
17: ; preds = %1
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = load i8*, i8** %3
%21 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = icmp sge i32 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24, %17
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
store i8* null, i8** %2
br label %33
31: ; preds = %24
%32 = load i8*, i8** %6
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %28, %16
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@.str = [9 x i8] c"/lxcapi.\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @lxclock_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = add nsw i32 %3, %2
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = tail call i32 @snprintf(i8* %6, i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = icmp slt i32 %9, 0
%11 = icmp sgt i32 %9, %4
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @free(i8* %6)
br label %15
15: ; preds = %8, %1, %13
%16 = phi i8* [ null, %13 ], [ null, %1 ], [ %6, %8 ]
ret i8* %16
}