#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*/ __fmt;

/* Variables and functions */
int /*<<< orphan*/ strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
unsigned int strlen(char const *);
const char *sanitize_format(const char *fmt) {
  static char __fmt[1024];
  unsigned int len;
  if (!strchr(fmt, '\n'))
    return fmt;
  len = strlen(fmt);
  if (len >= sizeof(__fmt))
    return fmt;
  strcpy(__fmt, fmt);
  while (len-- && __fmt[len] == '\n')
    __fmt[len] = '\0';
  while (len) {
    if (__fmt[len] == '\n')
      __fmt[len] = ' ';
    --len;
  }
  return __fmt;
}


x86 assembly (clang, -O0):
<sanitize_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
cmp    $0x0,%eax
jne    1160 <sanitize_format+0x30>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1240 <sanitize_format+0x110>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    $0x400,%rax
jb     1188 <sanitize_format+0x58>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1240 <sanitize_format+0x110>
mov    -0x10(%rbp),%rsi
lea    0x2ebd(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     11ca <sanitize_format+0x9a>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2e93(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11da <sanitize_format+0xaa>
jmp    11ef <sanitize_format+0xbf>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2e6a(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    1198 <sanitize_format+0x68>
jmp    11f4 <sanitize_format+0xc4>
cmpl   $0x0,-0x14(%rbp)
je     1235 <sanitize_format+0x105>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2e46(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1227 <sanitize_format+0xf7>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2e2d(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <sanitize_format+0xc4>
lea    0x2e14(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_format>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %eax,%eax
je     1155 <sanitize_format+0x25>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x3ff,%eax
jbe    1161 <sanitize_format+0x31>
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %eax,%ebx
lea    0x2ee6(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
test   %ebx,%ebx
je     1193 <sanitize_format+0x63>
add    $0xffffffff,%ebx
nopl   0x0(%rax)
mov    %ebx,%eax
cmpb   $0xa,(%rax,%r14,1)
jne    119a <sanitize_format+0x6a>
movb   $0x0,(%rax,%r14,1)
add    $0xffffffff,%ebx
jb     1180 <sanitize_format+0x50>
mov    $0xffffffff,%ebx
jmp    119e <sanitize_format+0x6e>
test   %ebx,%ebx
je     1158 <sanitize_format+0x28>
mov    %ebx,%eax
add    $0xffffffff,%ebx
cmp    $0x7,%ebx
jb     12dd <sanitize_format+0x1ad>
add    $0x1,%rbx
mov    %rbx,%r8
and    $0xfffffffffffffff8,%r8
mov    %r8,%rdx
neg    %rdx
lea    0x2e8c(%rip),%r14
lea    (%rax,%r14,1),%rsi
add    $0xfffffffffffffff9,%rsi
sub    %r8,%rax
xor    %edi,%edi
pxor   %xmm0,%xmm0
movdqa 0xe23(%rip),%xmm1
movdqa 0xe2b(%rip),%xmm2
jmp    11fd <sanitize_format+0xcd>
nopw   0x0(%rax,%rax,1)
add    $0xfffffffffffffff8,%rdi
cmp    %rdi,%rdx
je     12d4 <sanitize_format+0x1a4>
movq   (%rsi,%rdi,1),%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm4
packuswb %xmm4,%xmm4
movdqa %xmm4,%xmm3
pcmpeqb %xmm1,%xmm3
movd   %xmm3,%ecx
test   $0x1,%cl
je     122f <sanitize_format+0xff>
movb   $0x20,0x7(%rsi,%rdi,1)
movdqa %xmm3,%xmm5
pslld  $0x8,%xmm5
movd   %xmm5,%ecx
shr    $0x10,%ecx
test   $0x1,%cl
je     1249 <sanitize_format+0x119>
movb   $0x20,0x6(%rsi,%rdi,1)
pshuflw $0x55,%xmm4,%xmm5
pcmpeqb %xmm1,%xmm5
pextrw $0x2,%xmm5,%ecx
test   $0x1,%cl
je     1261 <sanitize_format+0x131>
movb   $0x20,0x5(%rsi,%rdi,1)
movdqa %xmm3,%xmm5
psllq  $0x18,%xmm5
pextrw $0x3,%xmm5,%ecx
test   $0x1,%cl
je     1279 <sanitize_format+0x149>
movb   $0x20,0x4(%rsi,%rdi,1)
pshufd $0x55,%xmm4,%xmm4
pcmpeqb %xmm2,%xmm4
pextrw $0x4,%xmm4,%ecx
test   $0x1,%cl
je     1291 <sanitize_format+0x161>
movb   $0x20,0x3(%rsi,%rdi,1)
movdqa %xmm3,%xmm4
pslldq $0x5,%xmm4
pextrw $0x5,%xmm4,%ecx
test   $0x1,%cl
je     12a9 <sanitize_format+0x179>
movb   $0x20,0x2(%rsi,%rdi,1)
pextrw $0x3,%xmm3,%ecx
test   $0x1,%cl
je     12b8 <sanitize_format+0x188>
movb   $0x20,0x1(%rsi,%rdi,1)
pslldq $0x7,%xmm3
pextrw $0x7,%xmm3,%ecx
test   $0x1,%cl
je     11f0 <sanitize_format+0xc0>
movb   $0x20,(%rsi,%rdi,1)
jmp    11f0 <sanitize_format+0xc0>
cmp    %r8,%rbx
je     1158 <sanitize_format+0x28>
lea    0x2d6c(%rip),%r14
jmp    12fc <sanitize_format+0x1cc>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rax
test   %eax,%eax
je     1158 <sanitize_format+0x28>
cmpb   $0xa,(%rax,%r14,1)
jne    12f0 <sanitize_format+0x1c0>
movb   $0x20,(%rax,%r14,1)
jmp    12f0 <sanitize_format+0x1c0>

LLVM IR (-O0):
@sanitize_format.__fmt = internal global [1024 x i8] zeroinitializer
define i8* @sanitize_format(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strchr(i8* %5, i8 signext 10)
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
store i8* %9, i8** %2
br label %57
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = icmp uge i64 %14, 1024
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = load i8*, i8** %3
store i8* %17, i8** %2
br label %57
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %34, %18
%22 = load i32, i32* %4
%23 = add i32 %22, -1
store i32 %23, i32* %4
%24 = icmp ne i32 %22, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32, i32* %4
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br label %32
32: ; preds = %25, %21
%33 = phi i1 [ false, %21 ], [ %31, %25 ]
br i1 %33, label %34, label %38
34: ; preds = %32
%35 = load i32, i32* %4
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %36
store i8 0, i8* %37
br label %21
38: ; preds = %32
br label %39
39: ; preds = %53, %38
%40 = load i32, i32* %4
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %56
42: ; preds = %39
%43 = load i32, i32* %4
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i32, i32* %4
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %51
store i8 32, i8* %52
br label %53
53: ; preds = %49, %42
%54 = load i32, i32* %4
%55 = add i32 %54, -1
store i32 %55, i32* %4
br label %39
56: ; preds = %39
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 0), i8** %2
br label %57
57: ; preds = %56, %16, %8
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@sanitize_format.__fmt = internal global [1024 x i8] zeroinitializer
define i8* @sanitize_format(i8* %0) {
%2 = tail call i32 @strchr(i8* %0, i8 signext 10)
%3 = icmp eq i32 %2, 0
br i1 %3, label %95, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp ugt i32 %5, 1023
br i1 %6, label %95, label %7
7: ; preds = %4
%8 = tail call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 0), i8* %0)
%9 = icmp eq i32 %5, 0
br i1 %9, label %21, label %10
10: ; preds = %7, %17
%11 = phi i32 [ %12, %17 ], [ %5, %7 ]
%12 = add i32 %11, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %19
17: ; preds = %10
store i8 0, i8* %14
%18 = icmp eq i32 %12, 0
br i1 %18, label %21, label %10
19: ; preds = %10
%20 = icmp eq i32 %12, 0
br i1 %20, label %95, label %21
21: ; preds = %17, %7, %19
%22 = phi i32 [ %12, %19 ], [ -1, %7 ], [ -1, %17 ]
%23 = zext i32 %22 to i64
%24 = add i32 %22, -1
%25 = zext i32 %24 to i64
%26 = add nuw nsw i64 %25, 1
%27 = icmp ult i32 %24, 7
br i1 %27, label %83, label %28
28: ; preds = %21
%29 = and i64 %26, 8589934584
%30 = sub nsw i64 %23, %29
br label %31
31: ; preds = %78, %28
%32 = phi i64 [ 0, %28 ], [ %79, %78 ]
%33 = sub i64 %23, %32
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 -7
%36 = bitcast i8* %35 to <8 x i8>*
%37 = load <8 x i8>, <8 x i8>* %36
%38 = shufflevector <8 x i8> %37, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%39 = icmp eq <8 x i8> %38, <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
%40 = extractelement <8 x i1> %39, i64 0
br i1 %40, label %41, label %43
41: ; preds = %31
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %33
store i8 32, i8* %42
br label %43
43: ; preds = %41, %31
%44 = extractelement <8 x i1> %39, i64 1
br i1 %44, label %45, label %48
45: ; preds = %43
%46 = add i64 %33, -1
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %46
store i8 32, i8* %47
br label %48
48: ; preds = %45, %43
%49 = extractelement <8 x i1> %39, i64 2
br i1 %49, label %50, label %53
50: ; preds = %48
%51 = add i64 %33, -2
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %51
store i8 32, i8* %52
br label %53
53: ; preds = %50, %48
%54 = extractelement <8 x i1> %39, i64 3
br i1 %54, label %55, label %58
55: ; preds = %53
%56 = add i64 %33, -3
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %56
store i8 32, i8* %57
br label %58
58: ; preds = %55, %53
%59 = extractelement <8 x i1> %39, i64 4
br i1 %59, label %60, label %63
60: ; preds = %58
%61 = add i64 %33, -4
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %61
store i8 32, i8* %62
br label %63
63: ; preds = %60, %58
%64 = extractelement <8 x i1> %39, i64 5
br i1 %64, label %65, label %68
65: ; preds = %63
%66 = add i64 %33, -5
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %66
store i8 32, i8* %67
br label %68
68: ; preds = %65, %63
%69 = extractelement <8 x i1> %39, i64 6
br i1 %69, label %70, label %73
70: ; preds = %68
%71 = add i64 %33, -6
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %71
store i8 32, i8* %72
br label %73
73: ; preds = %70, %68
%74 = extractelement <8 x i1> %39, i64 7
br i1 %74, label %75, label %78
75: ; preds = %73
%76 = add i64 %33, -7
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %76
store i8 32, i8* %77
br label %78
78: ; preds = %75, %73
%79 = add nuw i64 %32, 8
%80 = icmp eq i64 %79, %29
br i1 %80, label %81, label %31
81: ; preds = %78
%82 = icmp eq i64 %26, %29
br i1 %82, label %95, label %83
83: ; preds = %21, %81
%84 = phi i64 [ %23, %21 ], [ %30, %81 ]
br label %85
85: ; preds = %83, %91
%86 = phi i64 [ %92, %91 ], [ %84, %83 ]
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 %86
%88 = load i8, i8* %87
%89 = icmp eq i8 %88, 10
br i1 %89, label %90, label %91
90: ; preds = %85
store i8 32, i8* %87
br label %91
91: ; preds = %90, %85
%92 = add nsw i64 %86, -1
%93 = trunc i64 %92 to i32
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %85
95: ; preds = %91, %81, %19, %4, %1
%96 = phi i8* [ %0, %1 ], [ %0, %4 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 0), %19 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 0), %81 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @sanitize_format.__fmt, i64 0, i64 0), %91 ]
ret i8* %96
}