#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 */
struct cmdline {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cmdline_insert_bytes(struct cmdline *, char *, long);
int /*<<< orphan*/ free(char *);
char *term_read_paste(long *);
void cmdline_insert_paste(struct cmdline *c) {
  long size, i;
  char *text = term_read_paste(&size);
  for (i = 0; i < size; i++) {
    if (text[i] == '\n')
      text[i] = ' ';
  }
  cmdline_insert_bytes(c, text, size);
  free(text);
}


x86 assembly (clang, -O0):
<cmdline_insert_paste>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <term_read_paste@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1196 <cmdline_insert_paste+0x66>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1180 <cmdline_insert_paste+0x50>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    1185 <cmdline_insert_paste+0x55>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <cmdline_insert_paste+0x21>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <cmdline_insert_bytes@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdline_insert_paste>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rdi
call   1050 <term_read_paste@plt>
mov    %rax,%rbx
mov    (%rsp),%rdx
test   %rdx,%rdx
jle    1169 <cmdline_insert_paste+0x39>
xor    %eax,%eax
jmp    1159 <cmdline_insert_paste+0x29>
nop
add    $0x1,%rax
cmp    %rdx,%rax
jge    1169 <cmdline_insert_paste+0x39>
cmpb   $0xa,(%rbx,%rax,1)
jne    1150 <cmdline_insert_paste+0x20>
movb   $0x20,(%rbx,%rax,1)
mov    (%rsp),%rdx
jmp    1150 <cmdline_insert_paste+0x20>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <cmdline_insert_bytes@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.cmdline = type { i32 }
define void @cmdline_insert_paste(%struct.cmdline* %0) {
%2 = alloca %struct.cmdline*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store %struct.cmdline* %0, %struct.cmdline** %2
%6 = call i8* @term_read_paste(i64* %3)
store i8* %6, i8** %5
store i64 0, i64* %4
br label %7
7: ; preds = %23, %1
%8 = load i64, i64* %4
%9 = load i64, i64* %3
%10 = icmp slt i64 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i8*, i8** %5
%13 = load i64, i64* %4
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = load i64, i64* %4
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 32, i8* %21
br label %22
22: ; preds = %18, %11
br label %23
23: ; preds = %22
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 1
store i64 %25, i64* %4
br label %7
26: ; preds = %7
%27 = load %struct.cmdline*, %struct.cmdline** %2
%28 = load i8*, i8** %5
%29 = load i64, i64* %3
%30 = call i32 @cmdline_insert_bytes(%struct.cmdline* %27, i8* %28, i64 %29)
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
ret void
}

LLVM IR (-O2):
%struct.cmdline = type { i32 }
define void @cmdline_insert_paste(%struct.cmdline* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i8* @term_read_paste(i64* %2)
%5 = load i64, i64* %2
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1, %15
%8 = phi i64 [ %16, %15 ], [ %5, %1 ]
%9 = phi i64 [ %17, %15 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %7
store i8 32, i8* %10
%14 = load i64, i64* %2
br label %15
15: ; preds = %7, %13
%16 = phi i64 [ %8, %7 ], [ %14, %13 ]
%17 = add nuw nsw i64 %9, 1
%18 = icmp slt i64 %17, %16
br i1 %18, label %7, label %19
19: ; preds = %15, %1
%20 = phi i64 [ %5, %1 ], [ %16, %15 ]
%21 = call i32 @cmdline_insert_bytes(%struct.cmdline* %0, i8* %4, i64 %20)
%22 = call i32 @free(i8* %4)
ret void
}