#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 */
scalar_t__ isprint(int);
int sanitise(unsigned char *opt, char *buf) {
  char *p;
  int i;
  *buf = 0;
  if (!opt)
    return 0;
  p = ((void *)&(((unsigned char *)(opt))[2u + (unsigned int)(0)]));
  for (i = ((int)(((unsigned char *)(opt))[1])); i > 0; i--) {
    char c = *p++;
    if (isprint((int)c))
      *buf++ = c;
  }
  *buf = 0;
  return 1;
}


x86 assembly (clang, -O0):
<sanitise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    113e <sanitise+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11bb <sanitise+0xab>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11ad <sanitise+0x9d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%edi
call   1030 <isprint@plt>
cmp    $0x0,%rax
je     119a <sanitise+0x8a>
mov    -0x25(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    119f <sanitise+0x8f>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <sanitise+0x45>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitise>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movb   $0x0,(%rsi)
test   %rdi,%rdi
je     1172 <sanitise+0x62>
mov    %rsi,%r14
mov    %rdi,%rbx
movzbl 0x1(%rdi),%ebp
test   %ebp,%ebp
je     1167 <sanitise+0x57>
add    $0x2,%rbx
add    $0x1,%ebp
jmp    114c <sanitise+0x3c>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1167 <sanitise+0x57>
movzbl (%rbx),%r15d
movsbl %r15b,%edi
call   1030 <isprint@plt>
test   %rax,%rax
je     1140 <sanitise+0x30>
mov    %r15b,(%r14)
add    $0x1,%r14
jmp    1140 <sanitise+0x30>
movb   $0x0,(%r14)
mov    $0x1,%eax
jmp    1174 <sanitise+0x64>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sanitise(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
store i8 0, i8* %9
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %41
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 2
store i8* %15, i8** %6
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
store i32 %19, i32* %7
br label %20
20: ; preds = %36, %13
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8, i8* %24
store i8 %26, i8* %8
%27 = load i8, i8* %8
%28 = sext i8 %27 to i32
%29 = call i64 @isprint(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %23
%32 = load i8, i8* %8
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
store i8 %32, i8* %33
br label %35
35: ; preds = %31, %23
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, -1
store i32 %38, i32* %7
br label %20
39: ; preds = %20
%40 = load i8*, i8** %5
store i8 0, i8* %40
store i32 1, i32* %3
br label %41
41: ; preds = %39, %12
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @sanitise(i8* %0, i8* nocapture writeonly %1) {
store i8 0, i8* %1
%3 = icmp eq i8* %0, null
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %4
%9 = zext i8 %6 to i32
%10 = getelementptr inbounds i8, i8* %0, i64 2
br label %11
11: ; preds = %8, %22
%12 = phi i32 [ %24, %22 ], [ %9, %8 ]
%13 = phi i8* [ %15, %22 ], [ %10, %8 ]
%14 = phi i8* [ %23, %22 ], [ %1, %8 ]
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %13
%17 = sext i8 %16 to i32
%18 = tail call i64 @isprint(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %11
%21 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %16, i8* %14
br label %22
22: ; preds = %20, %11
%23 = phi i8* [ %21, %20 ], [ %14, %11 ]
%24 = add nsw i32 %12, -1
%25 = icmp sgt i32 %12, 1
br i1 %25, label %11, label %26
26: ; preds = %22, %4
%27 = phi i8* [ %1, %4 ], [ %23, %22 ]
store i8 0, i8* %27
br label %28
28: ; preds = %2, %26
%29 = phi i32 [ 1, %26 ], [ 0, %2 ]
ret i32 %29
}