#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*/ printf(char *, long, ...);
long strlen(char *);
void truncate_utxbytes(char *utxbytes) {
  long i, n;
  n = strlen(utxbytes);
  if (n > 128) {
    for (i = n - 128; i < n; i++)
      if (utxbytes[i] != '0')
        printf("calc_raw_NXTtx: unexpected non-'0' byte (%c) %d\n", utxbytes[i],
               utxbytes[i]);
    utxbytes[n - 128] = 0;
  } else
    printf("utxlen.%ld\n", n);
}


x86 assembly (clang, -O0):
<truncate_utxbytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x80,-0x18(%rbp)
jle    11cd <truncate_utxbytes+0xad>
mov    -0x18(%rbp),%rax
sub    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11b5 <truncate_utxbytes+0x95>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     119f <truncate_utxbytes+0x7f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbq (%rax,%rcx,1),%rsi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a4 <truncate_utxbytes+0x84>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1155 <truncate_utxbytes+0x35>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x80,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11df <truncate_utxbytes+0xbf>
mov    -0x18(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncate_utxbytes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r13
cmp    $0x81,%rax
jl     1172 <truncate_utxbytes+0x52>
lea    -0x80(%r13),%r12
lea    0xeb9(%rip),%r15
mov    %r12,%rbx
jmp    1159 <truncate_utxbytes+0x39>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %r13,%rbx
jge    118c <truncate_utxbytes+0x6c>
movsbl (%r14,%rbx,1),%edx
cmp    $0x30,%edx
je     1150 <truncate_utxbytes+0x30>
movslq %edx,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1150 <truncate_utxbytes+0x30>
lea    0xeb8(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
movb   $0x0,(%r14,%r12,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [49 x i8] c"calc_raw_NXTtx: unexpected non-'0' byte (%c) %d\0A\00"
@.str.1 = [12 x i8] c"utxlen.%ld\0A\00"
define void @truncate_utxbytes(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp sgt i64 %7, 128
br i1 %8, label %9, label %44
9: ; preds = %1
%10 = load i64, i64* %4
%11 = sub nsw i64 %10, 128
store i64 %11, i64* %3
br label %12
12: ; preds = %36, %9
%13 = load i64, i64* %3
%14 = load i64, i64* %4
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %39
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i64, i64* %3
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 48
br i1 %22, label %23, label %35
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = load i64, i64* %3
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i64
%29 = load i8*, i8** %2
%30 = load i64, i64* %3
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %28, i32 %33)
br label %35
35: ; preds = %23, %16
br label %36
36: ; preds = %35
%37 = load i64, i64* %3
%38 = add nsw i64 %37, 1
store i64 %38, i64* %3
br label %12
39: ; preds = %12
%40 = load i8*, i8** %2
%41 = load i64, i64* %4
%42 = sub nsw i64 %41, 128
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
br label %47
44: ; preds = %1
%45 = load i64, i64* %4
%46 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %45)
br label %47
47: ; preds = %44, %39
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"calc_raw_NXTtx: unexpected non-'0' byte (%c) %d\0A\00"
@.str.1 = [12 x i8] c"utxlen.%ld\0A\00"
define void @truncate_utxbytes(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp sgt i64 %2, 128
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = add nsw i64 %2, -128
br label %6
6: ; preds = %4, %15
%7 = phi i64 [ %5, %4 ], [ %16, %15 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 48
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = sext i8 %9 to i32
%13 = sext i8 %9 to i64
%14 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %13, i32 %12)
br label %15
15: ; preds = %6, %11
%16 = add nsw i64 %7, 1
%17 = icmp slt i64 %16, %2
br i1 %17, label %6, label %18
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 0, i8* %19
br label %22
20: ; preds = %1
%21 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %2)
br label %22
22: ; preds = %20, %18
ret void
}