#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  FILE *file = fopen("input.txt", "r");
  char *feed = NULL;
  size_t len = 0;
  getline(&feed, &len, file);
  int sum = 0;
  int x1;
  int x2;
  for (int i = 0; i < len; i++) {
    x1 = atoi(feed[i]);
    x2 = atoi(feed[(i + 1) % len]);
    printf("%d, ", x1);
    if (x1 == x2) {
      sum += x1;
    }
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <getline@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x38(%rbp)
movslq -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    121d <main+0xdd>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax,%rdx,1),%edi
call   1050 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%esi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    120a <main+0xca>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    120f <main+0xcf>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    119c <main+0x5c>
mov    -0x2c(%rbp),%esi
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1040 <fopen@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1060 <getline@plt>
xor    %r15d,%r15d
cmpq   $0x0,0x8(%rsp)
je     1201 <main+0xc1>
xor    %r13d,%r13d
lea    0xe72(%rip),%r14
xor    %ebx,%ebx
jmp    11cf <main+0x8f>
xchg   %ax,%ax
mov    %rbx,%rax
xor    %edx,%edx
div    %rsi
movsbl (%rcx,%rdx,1),%edi
call   1050 <atoi@plt>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
cmp    %r12d,%ebp
cmovne %r13d,%ebp
add    %ebp,%r15d
cmp    %rbx,0x8(%rsp)
jbe    1201 <main+0xc1>
mov    0x10(%rsp),%rax
movsbl (%rax,%rbx,1),%edi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rcx
add    $0x1,%rbx
mov    0x8(%rsp),%rsi
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    11a0 <main+0x60>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
jmp    11a8 <main+0x68>
lea    0xe09(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%d, \00"
@.str.3 = [4 x i8] c"%d\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 i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
store i8* null, i8** %7
store i64 0, i64* %8
%14 = load i32*, i32** %6
%15 = call i32 @getline(i8** %7, i64* %8, i32* %14)
store i32 0, i32* %9
store i32 0, i32* %12
br label %16
16: ; preds = %47, %2
%17 = load i32, i32* %12
%18 = sext i32 %17 to i64
%19 = load i64, i64* %8
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %50
21: ; preds = %16
%22 = load i8*, i8** %7
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @atoi(i8 signext %26)
store i32 %27, i32* %10
%28 = load i8*, i8** %7
%29 = load i32, i32* %12
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = load i64, i64* %8
%33 = urem i64 %31, %32
%34 = getelementptr inbounds i8, i8* %28, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @atoi(i8 signext %35)
store i32 %36, i32* %11
%37 = load i32, i32* %10
%38 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %46
42: ; preds = %21
%43 = load i32, i32* %10
%44 = load i32, i32* %9
%45 = add nsw i32 %44, %43
store i32 %45, i32* %9
br label %46
46: ; preds = %42, %21
br label %47
47: ; preds = %46
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %16
50: ; preds = %16
%51 = load i32, i32* %9
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%d, \00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = call i32 @getline(i8** %3, i64* %4, i32* %5)
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %14, %2
%12 = phi i32 [ 0, %2 ], [ %31, %14 ]
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %12)
ret i32 0
14: ; preds = %2, %14
%15 = phi i64 [ %22, %14 ], [ 0, %2 ]
%16 = phi i32 [ %31, %14 ], [ 0, %2 ]
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 %15
%19 = load i8, i8* %18
%20 = call i32 @atoi(i8 signext %19)
%21 = load i8*, i8** %3
%22 = add nuw i64 %15, 1
%23 = load i64, i64* %4
%24 = urem i64 %22, %23
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @atoi(i8 signext %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%29 = icmp eq i32 %20, %27
%30 = select i1 %29, i32 %20, i32 0
%31 = add nsw i32 %30, %16
%32 = load i64, i64* %4
%33 = icmp ugt i64 %32, %22
br i1 %33, label %14, label %11
}