#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
char *get_new_value(char *, char, int);
char *piece_replace(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int piece_offset;
  char delimiter;
  char buffer[65536];
  char *new_value;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s delimiter piece_offset\n", argv[0]);
    return 0;
  }
  delimiter = *argv[1];
  piece_offset = atoi(argv[2]);
  while (get_line(buffer, stdin)) {
    if (!(new_value = get_new_value(buffer, delimiter, piece_offset))) {
      printf("%s\n", buffer);
    } else {
      printf("%s\n", piece_replace(buffer, delimiter, new_value, piece_offset));
    }
    fflush(stdout);
  }
  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   $0x3,-0x8(%rbp)
je     11bb <main+0x4b>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    -0x10020(%rbp),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1273 <main+0x103>
lea    -0x10020(%rbp),%rdi
mov    -0x15(%rbp),%al
mov    -0x14(%rbp),%edx
movsbl %al,%esi
call   1090 <get_new_value@plt>
mov    %rax,-0x10028(%rbp)
cmp    $0x0,%rax
jne    1235 <main+0xc5>
lea    -0x10020(%rbp),%rsi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
jmp    1260 <main+0xf0>
lea    -0x10020(%rbp),%rdi
mov    -0x15(%rbp),%al
mov    -0x10028(%rbp),%rdx
mov    -0x14(%rbp),%ecx
movsbl %al,%esi
call   1070 <piece_replace@plt>
mov    %rax,%rsi
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    11d8 <main+0x68>
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
cmp    $0x3,%edi
jne    121f <main+0xaf>
mov    0x8(%rsi),%rax
mov    0x10(%rsi),%rdi
mov    (%rax),%bl
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x2e45(%rip),%r12
mov    (%r12),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1237 <main+0xc7>
movsbl %bl,%ebp
mov    %rsp,%rbx
lea    0xe5d(%rip),%r15
mov    0x2e04(%rip),%r13
jmp    1205 <main+0x95>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
mov    %r14d,%ecx
call   1070 <piece_replace@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x0(%r13),%edi
call   1060 <fflush@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1237 <main+0xc7>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1090 <get_new_value@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %r15,%rdi
mov    %rbx,%rsi
jmp    11e6 <main+0x76>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdce(%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 = [34 x i8] c"Usage: %s delimiter piece_offset\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
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, 3
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 ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %52
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
br label %27
27: ; preds = %48, %18
%28 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i64 @get_line(i8* %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %51
32: ; preds = %27
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%34 = load i8, i8* %7
%35 = load i32, i32* %6
%36 = call i8* @get_new_value(i8* %33, i8 signext %34, i32 %35)
store i8* %36, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %41, label %38
38: ; preds = %32
%39 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %48
41: ; preds = %32
%42 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%43 = load i8, i8* %7
%44 = load i8*, i8** %9
%45 = load i32, i32* %6
%46 = call i8* @piece_replace(i8* %42, i8 signext %43, i8* %44, i32 %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %41, %38
%49 = load i32, i32* @stdout
%50 = call i32 @fflush(i32 %49)
br label %27
51: ; preds = %27
store i32 0, i32* %3
br label %52
52: ; preds = %51, %12
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: %s delimiter piece_offset\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
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, 3
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 ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %34
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 = load i32, i32* @stdin
%18 = call i64 @get_line(i8* %4, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %34, label %20
20: ; preds = %10, %28
%21 = call i8* @get_new_value(i8* %4, i8 signext %13, i32 %16)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %28
25: ; preds = %20
%26 = call i8* @piece_replace(i8* %4, i8 signext %13, i8* %21, i32 %16)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %23
%29 = load i32, i32* @stdout
%30 = call i32 @fflush(i32 %29)
%31 = load i32, i32* @stdin
%32 = call i64 @get_line(i8* %4, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %20
34: ; preds = %28, %10, %6
ret i32 0
}