#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__ m_len(int);
int /*<<< orphan*/ m_putc(int, int /*<<< orphan*/);
scalar_t__ mls(int, scalar_t__);
void normalize_str(int m) {
  if (m_len(m) > 0 && (*(char *)mls((m), (m_len(m) - 1))) == 10)
    (*(char *)mls((m), (m_len(m) - 1))) = 0;
  else
    m_putc(m, 0);
}


x86 assembly (clang, -O0):
<normalize_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <m_len@plt>
cmp    $0x0,%rax
jle    119b <normalize_str+0x6b>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <m_len@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rsi
sub    $0x1,%rsi
call   1050 <mls@plt>
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    119b <normalize_str+0x6b>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <m_len@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rsi
sub    $0x1,%rsi
call   1050 <mls@plt>
movb   $0x0,(%rax)
jmp    11a5 <normalize_str+0x75>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <m_putc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_str>:
push   %rbx
mov    %edi,%ebx
call   1030 <m_len@plt>
test   %rax,%rax
jle    116b <normalize_str+0x3b>
mov    %ebx,%edi
call   1030 <m_len@plt>
lea    -0x1(%rax),%rsi
mov    %ebx,%edi
call   1050 <mls@plt>
cmpb   $0xa,(%rax)
jne    116b <normalize_str+0x3b>
mov    %ebx,%edi
call   1030 <m_len@plt>
lea    -0x1(%rax),%rsi
mov    %ebx,%edi
call   1050 <mls@plt>
movb   $0x0,(%rax)
pop    %rbx
ret
mov    %ebx,%edi
xor    %esi,%esi
pop    %rbx
jmp    1040 <m_putc@plt>

LLVM IR (-O0):
define void @normalize_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i64 @m_len(i32 %3)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %1
%7 = load i32, i32* %2
%8 = load i32, i32* %2
%9 = call i64 @m_len(i32 %8)
%10 = sub nsw i64 %9, 1
%11 = call i64 @mls(i32 %7, i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %23
16: ; preds = %6
%17 = load i32, i32* %2
%18 = load i32, i32* %2
%19 = call i64 @m_len(i32 %18)
%20 = sub nsw i64 %19, 1
%21 = call i64 @mls(i32 %17, i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8 0, i8* %22
br label %26
23: ; preds = %6, %1
%24 = load i32, i32* %2
%25 = call i32 @m_putc(i32 %24, i32 0)
br label %26
26: ; preds = %23, %16
ret void
}

LLVM IR (-O2):
define void @normalize_str(i32 %0) {
%2 = tail call i64 @m_len(i32 %0)
%3 = icmp sgt i64 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = tail call i64 @m_len(i32 %0)
%6 = add nsw i64 %5, -1
%7 = tail call i64 @mls(i32 %0, i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %16
11: ; preds = %4
%12 = tail call i64 @m_len(i32 %0)
%13 = add nsw i64 %12, -1
%14 = tail call i64 @mls(i32 %0, i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8 0, i8* %15
br label %18
16: ; preds = %4, %1
%17 = tail call i32 @m_putc(i32 %0, i32 0)
br label %18
18: ; preds = %16, %11
ret void
}