#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 */
typedef scalar_t__ uid_t;

/* Variables and functions */
int /*<<< orphan*/ sc_must_snprintf(char *, size_t, char *, char *, ...);
void get_lock_name(char *lock_fname, size_t size, const char *scope,
                   uid_t uid) {
  if (uid == 0) {
    sc_must_snprintf(lock_fname, size, "%s.lock", scope ?: "");
  } else {
    sc_must_snprintf(lock_fname, size, "%s.%d.lock", scope ?: "", uid);
  }
}


x86 assembly (clang, -O0):
<get_lock_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <get_lock_name+0x81>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1162 <get_lock_name+0x52>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1172 <get_lock_name+0x62>
lea    0xea9(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    1172 <get_lock_name+0x62>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rcx
lea    0xe7b(%rip),%rdx
mov    $0x0,%al
call   1030 <sc_must_snprintf@plt>
jmp    11ee <get_lock_name+0xde>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     11c0 <get_lock_name+0xb0>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    11d0 <get_lock_name+0xc0>
lea    0xe4b(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11d0 <get_lock_name+0xc0>
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe21(%rip),%rdx
mov    $0x0,%al
call   1030 <sc_must_snprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lock_name>:
mov    %rcx,%r8
test   %rdx,%rdx
lea    0xef5(%rip),%rcx
cmovne %rdx,%rcx
test   %r8,%r8
je     1134 <get_lock_name+0x24>
lea    0xedb(%rip),%rdx
xor    %eax,%eax
jmp    1030 <sc_must_snprintf@plt>
lea    0xec5(%rip),%rdx
xor    %eax,%eax
jmp    1030 <sc_must_snprintf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%s.lock\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [11 x i8] c"%s.%d.lock\00"
define void @get_lock_name(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %4
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
br label %18
17: ; preds = %11
br label %18
18: ; preds = %17, %16
%19 = phi i8* [ %14, %16 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %17 ]
%20 = call i32 (i8*, i64, i8*, i8*, ...) @sc_must_snprintf(i8* %12, i64 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %32
21: ; preds = %4
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
br label %28
27: ; preds = %21
br label %28
28: ; preds = %27, %26
%29 = phi i8* [ %24, %26 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %27 ]
%30 = load i64, i64* %8
%31 = call i32 (i8*, i64, i8*, i8*, ...) @sc_must_snprintf(i8* %22, i64 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %29, i64 %30)
br label %32
32: ; preds = %28, %18
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s.lock\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [11 x i8] c"%s.%d.lock\00"
define void @get_lock_name(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = icmp eq i64 %3, 0
%6 = icmp eq i8* %2, null
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %2
br i1 %5, label %8, label %10
8: ; preds = %4
%9 = tail call i32 (i8*, i64, i8*, i8*, ...) @sc_must_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %12
10: ; preds = %4
%11 = tail call i32 (i8*, i64, i8*, i8*, ...) @sc_must_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %7, i64 %3)
br label %12
12: ; preds = %10, %8
ret void
}