#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 uint8_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strtoul(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  uint32_t offset, curpos, curarg;
  int c;
  if (argc < 3) {
    fprintf(stderr, "Need two or more args:  OFFSET VAL [VAL...]\n");
    return 1;
  }
  offset = (uint32_t)strtoul(argv[1], 0, 0);
  curarg = 2;
  for (curpos = 0; (c = fgetc(stdin)) != EOF; curpos++) {
    if (curpos == offset && curarg < argc) {
      c = (uint8_t)strtoul(argv[curarg++], 0, 0);
      offset++;
    }
    fputc(c, stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1181 <main+0x41>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123d <main+0xfd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <strtoul@plt>
mov    %rax,-0x18(%rbp)
movq   $0x2,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
je     1236 <main+0xf6>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1214 <main+0xd4>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jge    1214 <main+0xd4>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    (%rax,%rcx,8),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1040 <fputc@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <main+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     116f <main+0x2f>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%ebp
jmp    120e <main+0xce>
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x8(%rsi),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%r12
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%eax
je     120e <main+0xce>
mov    %r15d,%r15d
mov    $0x2,%ebp
xor    %ebx,%ebx
mov    0x2e17(%rip),%r13
jmp    11e8 <main+0xa8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
mov    0x0(%r13),%esi
mov    %eax,%edi
call   1040 <fputc@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%eax
je     120c <main+0xcc>
cmp    %r12,%rbx
jne    11c0 <main+0x80>
cmp    %r15,%rbp
jge    11c0 <main+0x80>
mov    (%r14,%rbp,8),%rdi
add    $0x1,%rbp
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
add    $0x1,%rbx
mov    %rbx,%r12
jmp    11c4 <main+0x84>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Need two or more args: OFFSET VAL [VAL...]\0A\00"
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %52
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strtoul(i8* %18, i32 0, i32 0)
store i64 %19, i64* %6
store i64 2, i64* %8
store i64 0, i64* %7
br label %20
20: ; preds = %48, %15
%21 = load i32, i32* @stdin
%22 = call i32 @fgetc(i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = load i64, i64* %7
%27 = load i64, i64* %6
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load i64, i64* %8
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %34, label %44
34: ; preds = %29
%35 = load i8**, i8*** %5
%36 = load i64, i64* %8
%37 = add nsw i64 %36, 1
store i64 %37, i64* %8
%38 = getelementptr inbounds i8*, i8** %35, i64 %36
%39 = load i8*, i8** %38
%40 = call i64 @strtoul(i8* %39, i32 0, i32 0)
%41 = trunc i64 %40 to i32
store i32 %41, i32* %9
%42 = load i64, i64* %6
%43 = add nsw i64 %42, 1
store i64 %43, i64* %6
br label %44
44: ; preds = %34, %29, %25
%45 = load i32, i32* %9
%46 = load i32, i32* @stdout
%47 = call i32 @fputc(i32 %45, i32 %46)
br label %48
48: ; preds = %44
%49 = load i64, i64* %7
%50 = add nsw i64 %49, 1
store i64 %50, i64* %7
br label %20
51: ; preds = %20
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 = [45 x i8] c"Need two or more args: OFFSET VAL [VAL...]\0A\00"
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %45
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strtoul(i8* %9, i32 0, i32 0)
%11 = load i32, i32* @stdin
%12 = tail call i32 @fgetc(i32 %11)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %45, label %15
15: ; preds = %7
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %15, %34
%18 = phi i32 [ %12, %15 ], [ %42, %34 ]
%19 = phi i64 [ 2, %15 ], [ %37, %34 ]
%20 = phi i64 [ 0, %15 ], [ %35, %34 ]
%21 = phi i64 [ %10, %15 ], [ %36, %34 ]
%22 = icmp eq i64 %20, %21
%23 = icmp slt i64 %19, %16
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %27, label %25
25: ; preds = %17
%26 = add nuw nsw i64 %20, 1
br label %34
27: ; preds = %17
%28 = add nsw i64 %19, 1
%29 = getelementptr inbounds i8*, i8** %1, i64 %19
%30 = load i8*, i8** %29
%31 = tail call i64 @strtoul(i8* %30, i32 0, i32 0)
%32 = trunc i64 %31 to i32
%33 = add nsw i64 %20, 1
br label %34
34: ; preds = %25, %27
%35 = phi i64 [ %26, %25 ], [ %33, %27 ]
%36 = phi i64 [ %21, %25 ], [ %33, %27 ]
%37 = phi i64 [ %19, %25 ], [ %28, %27 ]
%38 = phi i32 [ %18, %25 ], [ %32, %27 ]
%39 = load i32, i32* @stdout
%40 = tail call i32 @fputc(i32 %38, i32 %39)
%41 = load i32, i32* @stdin
%42 = tail call i32 @fgetc(i32 %41)
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %17
45: ; preds = %34, %7, %4
%46 = phi i32 [ 1, %4 ], [ 0, %7 ], [ 0, %34 ]
ret i32 %46
}