#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
unsigned long long strtoull(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "usage: %s <character number> <string>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  const unsigned long long pos = strtoull(argv[1], NULL, 0);
  char *str = argv[2];
  size_t cur_pos = 0;
  size_t line_num = 0;
  size_t char_in_line = 0;
  char *line = str;
  for (;;) {
    if (cur_pos == pos) {
      char *end = str;
      for (;;) {
        if (*end == '\n' || *end == '\0') {
          *end = '\0';
          break;
        }
        end++;
      }
      puts(line);
      size_t i;
      for (i = 0; i < char_in_line; i++) {
        putchar(' ');
      }
      putchar('^');
      putchar('\n');
      return 0;
    }
    if (*str == '\0') {
      fprintf(stderr,
              "*** End of string, position not found (%zu lines, %zu chars)",
              line_num, cur_pos);
      exit(EXIT_FAILURE);
    }
    if (*str == '\n') {
      line_num++;
      line = str + 1;
      char_in_line = 0;
    }
    cur_pos++;
    char_in_line++;
    str++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119c <main+0x4c>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoull@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1288 <main+0x138>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1215 <main+0xc5>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1221 <main+0xd1>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
jmp    1232 <main+0xe2>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11f5 <main+0xa5>
mov    -0x40(%rbp),%rdi
call   1040 <puts@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    126c <main+0x11c>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1243 <main+0xf3>
mov    $0x5e,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12c5 <main+0x175>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    12f5 <main+0x1a5>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11df <main+0x8f>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    123e <main+0xee>
mov    0x8(%r14),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoull@plt>
mov    0x10(%r14),%rsi
test   %rax,%rax
je     11e5 <main+0x95>
lea    (%rsi,%rax,1),%r8
xor    %ebx,%ebx
mov    %rsi,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
jmp    11ab <main+0x5b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdx
lea    (%rsi,%rcx,1),%rdi
add    $0x1,%rdi
xor    %ebx,%ebx
add    $0x1,%rcx
add    $0x1,%rbx
cmp    %rcx,%rax
je     11e0 <main+0x90>
movzbl (%rsi,%rcx,1),%r9d
cmp    $0xa,%r9b
je     1190 <main+0x40>
test   %r9b,%r9b
jne    119e <main+0x4e>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %r8,%rsi
jmp    11f0 <main+0xa0>
mov    %rsi,%rdi
nopl   0x0(%rax,%rax,1)
movzbl (%rsi),%eax
cmp    $0xa,%al
je     1201 <main+0xb1>
test   %al,%al
je     1201 <main+0xb1>
add    $0x1,%rsi
jmp    11f0 <main+0xa0>
movb   $0x0,(%rsi)
call   1040 <puts@plt>
test   %rbx,%rbx
je     1220 <main+0xd0>
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
jne    1210 <main+0xc0>
mov    $0x5e,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d2 <main+0x82>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"usage: %s <character number> <string>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [61 x i8] c"*** End of string, position not found (%zu lines, %zu chars)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strtoull(i8* %27, i32* null, i32 0)
store i64 %28, i64* %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
%32 = load i8*, i8** %7
store i8* %32, i8** %11
br label %33
33: ; preds = %91, %24
%34 = load i64, i64* %8
%35 = load i64, i64* %6
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %69
37: ; preds = %33
%38 = load i8*, i8** %7
store i8* %38, i8** %12
br label %39
39: ; preds = %51, %37
%40 = load i8*, i8** %12
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = load i8*, i8** %12
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %44, %39
%50 = load i8*, i8** %12
store i8 0, i8* %50
br label %54
51: ; preds = %44
%52 = load i8*, i8** %12
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %12
br label %39
54: ; preds = %49
%55 = load i8*, i8** %11
%56 = call i32 @puts(i8* %55)
store i64 0, i64* %13
br label %57
57: ; preds = %63, %54
%58 = load i64, i64* %13
%59 = load i64, i64* %10
%60 = icmp ult i64 %58, %59
br i1 %60, label %61, label %66
61: ; preds = %57
%62 = call i32 @putchar(i8 signext 32)
br label %63
63: ; preds = %61
%64 = load i64, i64* %13
%65 = add i64 %64, 1
store i64 %65, i64* %13
br label %57
66: ; preds = %57
%67 = call i32 @putchar(i8 signext 94)
%68 = call i32 @putchar(i8 signext 10)
ret i32 0
69: ; preds = %33
%70 = load i8*, i8** %7
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %69
%75 = load i32, i32* @stderr
%76 = load i64, i64* %9
%77 = load i64, i64* %8
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i64 %76, i64 %77)
%79 = load i32, i32* @EXIT_FAILURE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %69
%82 = load i8*, i8** %7
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 10
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = load i64, i64* %9
%88 = add i64 %87, 1
store i64 %88, i64* %9
%89 = load i8*, i8** %7
%90 = getelementptr inbounds i8, i8* %89, i64 1
store i8* %90, i8** %11
store i64 0, i64* %10
br label %91
91: ; preds = %86, %81
%92 = load i64, i64* %8
%93 = add i64 %92, 1
store i64 %93, i64* %8
%94 = load i64, i64* %10
%95 = add i64 %94, 1
store i64 %95, i64* %10
%96 = load i8*, i8** %7
%97 = getelementptr inbounds i8, i8* %96, i32 1
store i8* %97, i8** %7
br label %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"usage: %s <character number> <string>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [61 x i8] c"*** End of string, position not found (%zu lines, %zu chars)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoull(i8* nocapture %12, i32* null, i32 0)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = icmp eq i64 %13, 0
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = getelementptr i8, i8* %15, i64 %13
br label %39
19: ; preds = %54, %10
%20 = phi i8* [ %15, %10 ], [ %18, %54 ]
%21 = phi i64 [ 0, %10 ], [ %59, %54 ]
%22 = phi i8* [ %15, %10 ], [ %57, %54 ]
br label %23
23: ; preds = %19, %29
%24 = phi i8* [ %30, %29 ], [ %20, %19 ]
%25 = load i8, i8* %24
switch i8 %25, label %29 [
i8 10, label %26
i8 0, label %26
]
26: ; preds = %23, %23
store i8 0, i8* %24
%27 = tail call i32 @puts(i8* dereferenceable(1) %22)
%28 = icmp eq i64 %21, 0
br i1 %28, label %36, label %31
29: ; preds = %23
%30 = getelementptr inbounds i8, i8* %24, i64 1
br label %23
31: ; preds = %26, %31
%32 = phi i64 [ %34, %31 ], [ 0, %26 ]
%33 = tail call i32 @putchar(i8 signext 32)
%34 = add nuw i64 %32, 1
%35 = icmp eq i64 %34, %21
br i1 %35, label %36, label %31
36: ; preds = %31, %26
%37 = tail call i32 @putchar(i8 signext 94)
%38 = tail call i32 @putchar(i8 signext 10)
ret i32 0
39: ; preds = %17, %54
%40 = phi i8* [ %57, %54 ], [ %15, %17 ]
%41 = phi i64 [ %59, %54 ], [ 0, %17 ]
%42 = phi i64 [ %55, %54 ], [ 0, %17 ]
%43 = phi i64 [ %58, %54 ], [ 0, %17 ]
%44 = phi i8* [ %60, %54 ], [ %15, %17 ]
%45 = load i8, i8* %44
switch i8 %45, label %54 [
i8 0, label %46
i8 10, label %51
]
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i64 %42, i64 %43)
%49 = load i32, i32* @EXIT_FAILURE
%50 = tail call i32 @exit(i32 %49)
unreachable
51: ; preds = %39
%52 = add i64 %42, 1
%53 = getelementptr inbounds i8, i8* %44, i64 1
br label %54
54: ; preds = %39, %51
%55 = phi i64 [ %52, %51 ], [ %42, %39 ]
%56 = phi i64 [ 0, %51 ], [ %41, %39 ]
%57 = phi i8* [ %53, %51 ], [ %40, %39 ]
%58 = add nuw i64 %43, 1
%59 = add i64 %56, 1
%60 = getelementptr inbounds i8, i8* %44, i64 1
%61 = icmp eq i64 %58, %13
br i1 %61, label %19, label %39
}