#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 errno;
int snprintf(char *, int, char *, char *, long long);
int shmlog_get_name(char *prefix, long long seq, char *path, int path_size) {
  int ret;
  ret = snprintf(path, path_size, "%s-log-%019lld", prefix, seq);
  if (ret < 0 || ret >= path_size) {
    do {
      errno =
          errno < 0 ? errno : (-1 * ((((4) * 10000 + (281))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<shmlog_get_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xec3(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     115b <shmlog_get_name+0x4b>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     11b0 <shmlog_get_name+0xa0>
jmp    1160 <shmlog_get_name+0x50>
mov    0x2e79(%rip),%rax
cmpl   $0x0,(%rax)
jge    1181 <shmlog_get_name+0x71>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1198 <shmlog_get_name+0x88>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
add    $0x266a3a8,%eax
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    0x2e3e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <shmlog_get_name+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shmlog_get_name>:
push   %rbx
mov    %ecx,%ebx
mov    %rdx,%rax
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0xedd(%rip),%rdx
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <snprintf@plt>
test   %eax,%eax
js     113b <shmlog_get_name+0x2b>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
jge    113b <shmlog_get_name+0x2b>
pop    %rbx
ret
mov    0x2e9e(%rip),%rax
mov    (%rax),%ecx
mov    $0xfd995c58,%edx
sub    %ecx,%edx
test   %ecx,%ecx
cmovs  %ecx,%edx
mov    %edx,(%rax)
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"%s-log-%019lld\00"
@errno = global i32 0
define i32 @shmlog_get_name(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i32 @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1)
%6 = icmp sgt i32 %5, -1
%7 = icmp slt i32 %5, %3
%8 = and i1 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = load i32, i32* @errno
%11 = icmp slt i32 %10, 0
%12 = sub i32 -40281000, %10
%13 = select i1 %11, i32 %10, i32 %12
store i32 %13, i32* @errno
br label %14
14: ; preds = %4, %9
%15 = phi i32 [ -1, %9 ], [ 0, %4 ]
ret i32 %15
}