#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 */
size_t code128_encode_raw(char *, char *, size_t);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
size_t code128_encode_gs1(const char *s, char *out, size_t maxlength) {
  char raw[strlen(s) + 1];
  char *p = raw;
  for (; *s != '\0'; s++) {
    if (strncmp(s, "[FNC1]", 6) == 0) {
      *p++ = '\xf1';
      s += 5;
    } else if (*s != ' ') {
      *p++ = *s;
    }
  }
  *p = '\0';
  return code128_encode_raw(raw, out, maxlength);
}


x86 assembly (clang, -O0):
<code128_encode_gs1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x38(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     120d <code128_encode_gs1+0xdd>
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cb <code128_encode_gs1+0x9b>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0xf1,(%rax)
mov    -0x8(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    11f7 <code128_encode_gs1+0xc7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11f2 <code128_encode_gs1+0xc2>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
jmp    11f7 <code128_encode_gs1+0xc7>
jmp    11fc <code128_encode_gs1+0xcc>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1179 <code128_encode_gs1+0x49>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <code128_encode_raw@plt>
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<code128_encode_gs1>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,-0x30(%rbp)
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmpb   $0x0,(%rbx)
mov    %r14,%r12
je     11bd <code128_encode_gs1+0x8d>
lea    0xe90(%rip),%r13
mov    %r14,%r12
jmp    1197 <code128_encode_gs1+0x67>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0xf1,(%r12)
add    $0x1,%r12
add    $0x5,%rbx
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     11bd <code128_encode_gs1+0x8d>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1180 <code128_encode_gs1+0x50>
movzbl (%rbx),%eax
cmp    $0x20,%al
je     118d <code128_encode_gs1+0x5d>
mov    %al,(%r12)
add    $0x1,%r12
jmp    118d <code128_encode_gs1+0x5d>
movb   $0x0,(%r12)
mov    %r14,%rdi
mov    %r15,%rsi
mov    -0x30(%rbp),%rdx
call   1050 <code128_encode_raw@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"[FNC1]\00"
define i64 @code128_encode_gs1(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
store i8* %15, i8** %9
br label %16
16: ; preds = %42, %3
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %45
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %9
store i8 -15, i8* %26
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 5
store i8* %29, i8** %4
br label %41
30: ; preds = %21
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 32
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %9
store i8 %37, i8* %38
br label %40
40: ; preds = %35, %30
br label %41
41: ; preds = %40, %25
br label %42
42: ; preds = %41
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
br label %16
45: ; preds = %16
%46 = load i8*, i8** %9
store i8 0, i8* %46
%47 = load i8*, i8** %5
%48 = load i64, i64* %6
%49 = call i64 @code128_encode_raw(i8* %15, i8* %47, i64 %48)
%50 = load i8*, i8** %7
ret i64 %49
}

LLVM IR (-O2):
@.str = [7 x i8] c"[FNC1]\00"
define i64 @code128_encode_gs1(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %29, label %10
10: ; preds = %3, %23
%11 = phi i8* [ %25, %23 ], [ %7, %3 ]
%12 = phi i8* [ %26, %23 ], [ %0, %3 ]
%13 = tail call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = getelementptr inbounds i8, i8* %11, i64 1
store i8 -15, i8* %11
%17 = getelementptr inbounds i8, i8* %12, i64 5
br label %23
18: ; preds = %10
%19 = load i8, i8* %12
%20 = icmp eq i8 %19, 32
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %19, i8* %11
br label %23
23: ; preds = %15, %21, %18
%24 = phi i8* [ %17, %15 ], [ %12, %21 ], [ %12, %18 ]
%25 = phi i8* [ %16, %15 ], [ %22, %21 ], [ %11, %18 ]
%26 = getelementptr inbounds i8, i8* %24, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %10
29: ; preds = %23, %3
%30 = phi i8* [ %7, %3 ], [ %25, %23 ]
store i8 0, i8* %30
%31 = call i64 @code128_encode_raw(i8* %7, i8* %1, i64 %2)
ret i64 %31
}