#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
void safe_strncpy(char *out, unsigned out_len, char *in, unsigned in_len) {
  if (in_len >= out_len) {
    fprintf(stderr, "Impossible input line from dwarf.h. Giving up. \n");
    fprintf(stderr, "Length %u is too large, limited to %u.\n", in_len,
            out_len);
    exit(1);
  }
  strncpy(out, in, in_len);
}


x86 assembly (clang, -O0):
<safe_strncpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jb     1190 <safe_strncpy+0x60>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_strncpy>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
cmp    %esi,%ecx
jae    1148 <safe_strncpy+0x18>
mov    %rdx,%rsi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strncpy@plt>
mov    %esi,%ebp
mov    0x2e8f(%rip),%r14
mov    (%r14),%edi
lea    0xea5(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xec5(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Impossible input line from dwarf.h. Giving up. \0A\00"
@.str.1 = [40 x i8] c"Length %u is too large, limited to %u.\0A\00"
define void @safe_strncpy(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i32, i32* %8
%10 = load i32, i32* %6
%11 = icmp uge i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = call i32 @strncpy(i8* %21, i8* %22, i32 %23)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Impossible input line from dwarf.h. Giving up. \0A\00"
@.str.1 = [40 x i8] c"Length %u is too large, limited to %u.\0A\00"
define void @safe_strncpy(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp ult i32 %3, %1
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %1)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %3)
ret void
}