#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 */
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, short const);
int WebRtcNsx_get_version(char *versionStr, short length) {
  const char version[] = "NS\t3.1.0";
  const short versionLen = (short)strlen(version) + 1;
  if (versionStr == NULL) {
    return -1;
  }
  if (versionLen > length) {
    return -1;
  }
  strncpy(versionStr, version, versionLen);
  return 0;
}


x86 assembly (clang, -O0):
<WebRtcNsx_get_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    0xec6(%rip),%rax
mov    %rax,-0x1b(%rbp)
mov    0xec4(%rip),%al
mov    %al,-0x13(%rbp)
lea    -0x1b(%rbp),%rdi
call   1040 <strlen@plt>
cwtl
add    $0x1,%eax
mov    %ax,-0x1e(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <WebRtcNsx_get_version+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <WebRtcNsx_get_version+0x83>
movswl -0x1e(%rbp),%eax
movswl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jle    118b <WebRtcNsx_get_version+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <WebRtcNsx_get_version+0x83>
mov    -0x10(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
movswl -0x1e(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WebRtcNsx_get_version>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
movabs $0x302e312e3309534e,%rax
31 2e 30
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     1170 <WebRtcNsx_get_version+0x50>
add    $0x1,%ecx
cmp    %bp,%cx
jg     1170 <WebRtcNsx_get_version+0x50>
movswl %cx,%edx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.WebRtcNsx_get_version.version = [9 x i8] c"NS\093.1.0\00"
define i32 @WebRtcNsx_get_version(i8* %0, i16 signext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16
%6 = alloca [9 x i8]
%7 = alloca i16
store i8* %0, i8** %4
store i16 %1, i16* %5
%8 = bitcast [9 x i8]* %6 to i8*
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i16
%12 = sext i16 %11 to i32
%13 = add nsw i32 %12, 1
%14 = trunc i32 %13 to i16
store i16 %14, i16* %7
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %30
18: ; preds = %2
%19 = load i16, i16* %7
%20 = sext i16 %19 to i32
%21 = load i16, i16* %5
%22 = sext i16 %21 to i32
%23 = icmp sgt i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 -1, i32* %3
br label %30
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%28 = load i16, i16* %7
%29 = call i32 @strncpy(i8* %26, i8* %27, i16 signext %28)
store i32 0, i32* %3
br label %30
30: ; preds = %25, %24, %17
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@__const.WebRtcNsx_get_version.version = [9 x i8] c"NS\093.1.0\00"
define i32 @WebRtcNsx_get_version(i8* %0, i16 signext %1) {
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%5 = call i64 @strlen(i8* %4)
%6 = trunc i64 %5 to i16
%7 = add i16 %6, 1
%8 = icmp eq i8* %0, null
%9 = icmp sgt i16 %7, %1
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @strncpy(i8* %0, i8* %4, i16 signext %7)
br label %13
13: ; preds = %2, %11
%14 = phi i32 [ 0, %11 ], [ -1, %2 ]
ret i32 %14
}