#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 */
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
char *piece_replace(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int piece_offset;
  char delimiter;
  char buffer[65536];
  char *new_data;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s delimiter piece_offset new_data\n", argv[0]);
    return 0;
  }
  delimiter = *argv[1];
  piece_offset = atoi(argv[2]);
  new_data = argv[3];
  while (get_line(buffer, stdin)) {
    printf("%s\n", piece_replace(buffer, delimiter, new_data, piece_offset));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     119b <main+0x4b>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x10028(%rbp)
lea    -0x10020(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1216 <main+0xc6>
lea    -0x10020(%rbp),%rdi
mov    -0x15(%rbp),%al
mov    -0x10028(%rbp),%rdx
mov    -0x14(%rbp),%ecx
movsbl %al,%esi
call   1060 <piece_replace@plt>
mov    %rax,%rsi
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
jmp    11c7 <main+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11de <main+0x8e>
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%rdi
mov    (%rax),%bpl
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%r15
mov    0x2e61(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11f6 <main+0xa6>
movsbl %bpl,%ebp
mov    %rsp,%rbx
lea    0xe85(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1060 <piece_replace@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11b0 <main+0x60>
jmp    11f6 <main+0xa6>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe0f(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s delimiter piece_offset new_data\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca [65536 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %43
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
store i8 %22, i8* %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
store i8* %29, i8** %9
br label %30
30: ; preds = %35, %18
%31 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* @stdin
%33 = call i64 @get_line(i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%37 = load i8, i8* %7
%38 = load i8*, i8** %9
%39 = load i32, i32* %6
%40 = call i8* @piece_replace(i8* %36, i8 signext %37, i8* %38, i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %30
42: ; preds = %30
store i32 0, i32* %3
br label %43
43: ; preds = %42, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s delimiter piece_offset new_data\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %28
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = load i32, i32* @stdin
%20 = call i64 @get_line(i8* %4, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %10, %22
%23 = call i8* @piece_replace(i8* %4, i8 signext %13, i8* %18, i32 %16)
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @stdin
%26 = call i64 @get_line(i8* %4, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %22
28: ; preds = %22, %10, %6
ret i32 0
}