#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*/ assert_failed(char *, int);
void string_null_terminate(char *str, int len, int capacity) {
  do {
    if (!(len >= 0 && len <= capacity && capacity > 0))
      assert_failed("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/ZHAW-INES/"
                    "rioxo-uClinux-dist/refs/heads/master/buffer.c",
                    420);
  } while (0);
  if (len < capacity)
    *(str + len) = '\0';
  else if (len == capacity)
    *(str + len - 1) = '\0';
}


x86 assembly (clang, -O0):
<string_null_terminate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1142 <string_null_terminate+0x32>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1142 <string_null_terminate+0x32>
cmpl   $0x0,-0x10(%rbp)
jg     1153 <string_null_terminate+0x43>
lea    0xeb7(%rip),%rdi
mov    $0x1a4,%esi
call   1030 <assert_failed@plt>
jmp    1158 <string_null_terminate+0x48>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1175 <string_null_terminate+0x65>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1193 <string_null_terminate+0x83>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    118e <string_null_terminate+0x7e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    1193 <string_null_terminate+0x83>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_null_terminate>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
js     1133 <string_null_terminate+0x23>
cmp    %ebx,%ebp
jg     1133 <string_null_terminate+0x23>
test   %ebx,%ebx
jle    1133 <string_null_terminate+0x23>
cmp    %ebx,%ebp
jge    1148 <string_null_terminate+0x38>
movslq %ebp,%rax
add    %rax,%r14
jmp    1154 <string_null_terminate+0x44>
lea    0xec6(%rip),%rdi
mov    $0x1a4,%esi
call   1030 <assert_failed@plt>
cmp    %ebx,%ebp
jl     112b <string_null_terminate+0x1b>
jne    1158 <string_null_terminate+0x48>
movslq %ebp,%rax
add    %rax,%r14
add    $0xffffffffffffffff,%r14
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ZHAW-INES/rioxo-uClinux-dist/refs/heads/master/buffer.c\00"
define void @string_null_terminate(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %7
7: ; preds = %3
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14, %10, %7
%18 = call i32 @assert_failed(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 420)
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
br label %40
29: ; preds = %20
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 -1
store i8 0, i8* %38
br label %39
39: ; preds = %33, %29
br label %40
40: ; preds = %39, %24
ret void
}

LLVM IR (-O2):
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ZHAW-INES/rioxo-uClinux-dist/refs/heads/master/buffer.c\00"
define void @string_null_terminate(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, -1
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = icmp sle i32 %1, %2
%7 = icmp sgt i32 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %5, %3
%10 = tail call i32 @assert_failed(i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 420)
br label %11
11: ; preds = %9, %5
%12 = icmp slt i32 %1, %2
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = sext i32 %1 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
br label %22
16: ; preds = %11
%17 = icmp eq i32 %1, %2
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = sext i32 %1 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 -1
br label %22
22: ; preds = %13, %18
%23 = phi i8* [ %21, %18 ], [ %15, %13 ]
store i8 0, i8* %23
br label %24
24: ; preds = %22, %16
ret void
}