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

/* Variables and functions */
int /*<<< orphan*/ b_gets(int, char *);
int /*<<< orphan*/ b_lineid(int);
int expand(char *, char *, int);
int /*<<< orphan*/ repl_text(int, int /*<<< orphan*/, int, int, char *);
void replace(int row, int line, int useful_row) {
  int nsegs;
  char buf[1000 - 1], expanded[1000 + 100];
  b_gets(line, buf);
  nsegs = expand(expanded, buf, sizeof(expanded));
  repl_text(row, b_lineid(line), nsegs, useful_row, expanded);
}


x86 assembly (clang, -O0):
<replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x400(%rbp),%rsi
call   1040 <b_gets@plt>
lea    -0x850(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    $0x44c,%edx
call   1050 <expand@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x854(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <b_lineid@plt>
mov    -0x854(%rbp),%edi
mov    %eax,%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    -0x850(%rbp),%r8
call   1060 <repl_text@plt>
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x840,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    %rsp,%rbx
mov    %esi,%edi
mov    %rbx,%rsi
call   1040 <b_gets@plt>
lea    0x3f0(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x44c,%edx
call   1050 <expand@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <b_lineid@plt>
mov    %r15d,%edi
mov    %eax,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %r12,%r8
call   1060 <repl_text@plt>
add    $0x840,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @replace(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [999 x i8]
%9 = alloca [1100 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = getelementptr inbounds [999 x i8], [999 x i8]* %8, i64 0, i64 0
%12 = call i32 @b_gets(i32 %10, i8* %11)
%13 = getelementptr inbounds [1100 x i8], [1100 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds [999 x i8], [999 x i8]* %8, i64 0, i64 0
%15 = call i32 @expand(i8* %13, i8* %14, i32 1100)
store i32 %15, i32* %7
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 @b_lineid(i32 %17)
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = getelementptr inbounds [1100 x i8], [1100 x i8]* %9, i64 0, i64 0
%22 = call i32 @repl_text(i32 %16, i32 %18, i32 %19, i32 %20, i8* %21)
ret void
}

LLVM IR (-O2):
define void @replace(i32 %0, i32 %1, i32 %2) {
%4 = alloca [999 x i8]
%5 = alloca [1100 x i8]
%6 = getelementptr inbounds [999 x i8], [999 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1100 x i8], [1100 x i8]* %5, i64 0, i64 0
%8 = call i32 @b_gets(i32 %1, i8* %6)
%9 = call i32 @expand(i8* %7, i8* %6, i32 1100)
%10 = call i32 @b_lineid(i32 %1)
%11 = call i32 @repl_text(i32 %0, i32 %10, i32 %9, i32 %2, i8* %7)
ret void
}