#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 */
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ata_id_string(int /*<<< orphan*/ const *, unsigned char *,
                                 unsigned int, unsigned int);
int strnlen(char const *, unsigned int);
void ata_id_c_string(const uint16_t *id, unsigned char *s, unsigned int ofs,
                     unsigned int len) {
  unsigned char *p;
  ata_id_string(id, s, ofs, len - 1);
  p = s + strnlen((const char *)s, len - 1);
  while (p > s && p[-1] == ' ')
    p--;
  *p = '\0';
}


x86 assembly (clang, -O0):
<ata_id_c_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
call   1040 <ata_id_string@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
call   1030 <strnlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x29(%rbp)
jbe    1197 <ata_id_c_string+0x77>
mov    -0x20(%rbp),%rax
movzbl -0x1(%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a7 <ata_id_c_string+0x87>
jmp    11b8 <ata_id_c_string+0x98>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1173 <ata_id_c_string+0x53>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ata_id_c_string>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    -0x1(%rcx),%ebp
mov    %ebp,%ecx
call   1040 <ata_id_string@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <strnlen@plt>
movslq %eax,%rcx
add    %rbx,%rcx
mov    %rcx,%rax
cmp    %rbx,%rcx
jbe    1152 <ata_id_c_string+0x32>
lea    -0x1(%rax),%rcx
cmpb   $0x20,-0x1(%rax)
je     1140 <ata_id_c_string+0x20>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @ata_id_c_string(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = sub i32 %13, 1
%15 = call i32 @ata_id_string(i32* %10, i8* %11, i32 %12, i32 %14)
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = load i32, i32* %8
%19 = sub i32 %18, 1
%20 = call i32 @strnlen(i8* %17, i32 %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
store i8* %22, i8** %9
br label %23
23: ; preds = %35, %4
%24 = load i8*, i8** %9
%25 = load i8*, i8** %6
%26 = icmp ugt i8* %24, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i64 -1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 32
br label %33
33: ; preds = %27, %23
%34 = phi i1 [ false, %23 ], [ %32, %27 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %9
br label %23
38: ; preds = %33
%39 = load i8*, i8** %9
store i8 0, i8* %39
ret void
}

LLVM IR (-O2):
define void @ata_id_c_string(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = add i32 %3, -1
%6 = tail call i32 @ata_id_string(i32* %0, i8* %1, i32 %2, i32 %5)
%7 = tail call i32 @strnlen(i8* %1, i32 %5)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
br label %10
10: ; preds = %13, %4
%11 = phi i8* [ %9, %4 ], [ %14, %13 ]
%12 = icmp ugt i8* %11, %1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 -1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 32
br i1 %16, label %10, label %17
17: ; preds = %10, %13
store i8 0, i8* %11
ret void
}