#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ err(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ errx(int, char *);
char *malloc(size_t);
int snprintf(char *, size_t, char const *, char const *);
int strlen(char const *);
char *strtopat(const char *s) {
  const char *fmt = "[^%s\f\n\r\t]+";
  char *pat;
  size_t len;
  int n;
  len = strlen(s) + strlen(fmt) + 1;
  if ((pat = malloc(len)) == NULL)
    err(1, NULL);
  n = snprintf(pat, len, fmt, s);
  if (n == -1 || n >= (ssize_t)len)
    errx(1, "pattern too long");
  return pat;
}


x86 assembly (clang, -O0):
<strtopat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b1 <strtopat+0x61>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <err@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
call   1050 <snprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     11e2 <strtopat+0x92>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    %ecx,%eax
jl     11f3 <strtopat+0xa3>
mov    $0x1,%edi
lea    0xe1d(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtopat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    0xe95(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    (%rbx,%r14,1),%eax
add    $0x1,%eax
movslq %eax,%r13
mov    %r13,%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1198 <strtopat+0x48>
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <err@plt>
lea    0xe61(%rip),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rcx
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
je     11b9 <strtopat+0x69>
add    %r14d,%ebx
cmp    %ebx,%eax
jle    11ca <strtopat+0x7a>
lea    0xe4b(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"[^%s\0C\0A\0D\09]+\00"
@.str.1 = [17 x i8] c"pattern too long\00"
define i8* @strtopat(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @err(i32 1, i32* null)
br label %19
19: ; preds = %17, %1
%20 = load i8*, i8** %4
%21 = load i64, i64* %5
%22 = load i8*, i8** %3
%23 = load i8*, i8** %2
%24 = call i32 @snprintf(i8* %20, i64 %21, i8* %22, i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %32, label %27
27: ; preds = %19
%28 = load i32, i32* %6
%29 = load i64, i64* %5
%30 = trunc i64 %29 to i32
%31 = icmp sge i32 %28, %30
br i1 %31, label %32, label %34
32: ; preds = %27, %19
%33 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
@.str = [11 x i8] c"[^%s\0C\0A\0D\09]+\00"
@.str.1 = [17 x i8] c"pattern too long\00"
define i8* @strtopat(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = add nsw i32 %3, %2
%5 = add nsw i32 %4, 1
%6 = sext i32 %5 to i64
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @err(i32 1, i32* null)
br label %11
11: ; preds = %9, %1
%12 = tail call i32 @snprintf(i8* %7, i64 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = icmp eq i32 %12, -1
%14 = icmp sgt i32 %12, %4
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %11, %16
ret i8* %7
}