#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*/ vassert(int /*<<< orphan*/, char *);
char *strcut(char *str, size_t count) {
  char *res = str;
  vassert(str != NULL, "str == NULL");
  if (count > 0) {
    str += count;
    while (*str) {
      *(str - count) = *str;
      str++;
    }
    *(str - count) = '\0';
  }
  return res;
}


x86 assembly (clang, -O0):
<strcut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xec4(%rip),%rsi
call   1030 <vassert@plt>
cmpq   $0x0,-0x10(%rbp)
jbe    1197 <strcut+0x87>
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1189 <strcut+0x79>
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
sub    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1158 <strcut+0x48>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
sub    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcut>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
lea    0xed6(%rip),%rsi
call   1030 <vassert@plt>
test   %rbx,%rbx
je     116b <strcut+0x5b>
mov    (%r14,%rbx,1),%cl
mov    %rbx,%rax
neg    %rax
test   %cl,%cl
je     1164 <strcut+0x54>
mov    %r14,%rdx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %cl,(%rdx)
movzbl 0x1(%rdx,%rbx,1),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1150 <strcut+0x40>
add    %rdx,%rbx
jmp    1167 <strcut+0x57>
add    %r14,%rbx
movb   $0x0,(%rbx,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"str == NULL\00"
define i8* @strcut(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @vassert(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i64, i64* %4
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %2
%14 = load i64, i64* %4
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 %14
store i8* %16, i8** %3
br label %17
17: ; preds = %21, %13
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = load i8*, i8** %3
%25 = load i64, i64* %4
%26 = sub i64 0, %25
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %17
30: ; preds = %17
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = sub i64 0, %32
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %30, %2
%36 = load i8*, i8** %5
ret i8* %36
}

LLVM IR (-O2):
@.str = [12 x i8] c"str == NULL\00"
define i8* @strcut(i8* returned %0, i64 %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @vassert(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %1, 0
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 %1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
%11 = sub i64 0, %1
br i1 %10, label %19, label %12
12: ; preds = %7, %12
%13 = phi i8 [ %17, %12 ], [ %9, %7 ]
%14 = phi i8* [ %16, %12 ], [ %8, %7 ]
%15 = getelementptr inbounds i8, i8* %14, i64 %11
store i8 %13, i8* %15
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %12
19: ; preds = %12, %7
%20 = phi i8* [ %8, %7 ], [ %16, %12 ]
%21 = getelementptr inbounds i8, i8* %20, i64 %11
store i8 0, i8* %21
br label %22
22: ; preds = %19, %2
ret i8* %0
}