#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 get_path(long long base_seq, char *buf, int buf_sz, char *base_dir) {
  int ret;
  ret = snprintf(buf, buf_sz, "%s/%019lld.log", base_dir, base_seq);
  if (ret < 0 || ret >= buf_sz) {
    do {
      errno =
          errno < 0 ? errno : (-1 * ((((2) * 10000 + (257))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  return 0;
}


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

x86 assembly (clang, -O2):
<get_path>:
push   %rbx
mov    %edx,%ebx
mov    %rdi,%r8
lea    0xee3(%rip),%rdx
mov    %rsi,%rdi
mov    %ebx,%esi
call   1030 <snprintf@plt>
test   %eax,%eax
js     1135 <get_path+0x25>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
jge    1135 <get_path+0x25>
pop    %rbx
ret
mov    0x2ea4(%rip),%rax
mov    (%rax),%ecx
mov    $0xfecae718,%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/%019lld.log\00"
@errno = global i32 0
define i32 @get_path(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i64 %0, i64* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i8*, i8** %7
%12 = load i32, i32* %8
%13 = load i8*, i8** %9
%14 = load i64, i64* %6
%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* %8
%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 20257000, %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/%019lld.log\00"
@errno = global i32 0
define i32 @get_path(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %3, i64 %0)
%6 = icmp sgt i32 %5, -1
%7 = icmp slt i32 %5, %2
%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 -20257000, %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
}