#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ get_line(char *, int /*<<< orphan*/);
char *insert_string(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char buffer[1024] = {0};
  char *sub_string;
  int position;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s sub_string position\n", argv[0]);
    exit(1);
  }
  sub_string = argv[1];
  position = atoi(argv[2]);
  if (position < 0) {
    fprintf(stderr, "Only natural values allowed for position\n");
    exit(1);
  }
  while (get_line(buffer, stdin)) {
    printf("%s\n", insert_string(buffer, sub_string, position));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
je     11ce <main+0x5e>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x418(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jge    121e <main+0xae>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1223 <main+0xb3>
lea    -0x410(%rbp),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     126f <main+0xff>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rsi
mov    -0x41c(%rbp),%edx
call   1060 <insert_string@plt>
mov    %rax,%rsi
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
jmp    1223 <main+0xb3>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x3,%ebp
jne    121b <main+0xab>
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
js     123f <main+0xcf>
mov    %eax,%ebp
mov    0x2e2e(%rip),%r12
mov    (%r12),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1209 <main+0x99>
mov    %rsp,%rbx
lea    0xe74(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <insert_string@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s sub_string position\0A\00"
@.str.1 = [42 x i8] c"Only natural values allowed for position\0A\00"
@stdin = global i32 0
@.str.2 = [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 [1024 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [1024 x i8]* %6 to i8*
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
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 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%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* %8
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %19
br label %34
34: ; preds = %39, %33
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i64 @get_line(i8* %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = load i8*, i8** %7
%42 = load i32, i32* %8
%43 = call i8* @insert_string(i8* %40, i8* %41, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %34
45: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s sub_string position\0A\00"
@.str.1 = [42 x i8] c"Only natural values allowed for position\0A\00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%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 = icmp slt i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = load i32, i32* @stdin
%20 = call i64 @get_line(i8* %4, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %26
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18, %26
%27 = call i8* @insert_string(i8* %4, i8* %13, i32 %16)
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @stdin
%30 = call i64 @get_line(i8* %4, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %26
32: ; preds = %26, %18
ret i32 0
}