#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*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
main() {
  int offset = 0;
  char buffer[1024];
  fgets(buffer, 1024, stdin);
  offset += strlen(buffer);
  while (fgets(buffer, 1024, stdin) != NULL) {
    putc((offset & 0xff000000) >> 24, stdout);
    putc((offset & 0xff0000) >> 16, stdout);
    putc((offset & 0xff00) >> 8, stdout);
    putc((offset & 0xff), stdout);
    offset += strlen(buffer);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1223 <main+0xf3>
mov    -0x8(%rbp),%edi
and    $0xff000000,%edi
shr    $0x18,%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
mov    -0x8(%rbp),%edi
and    $0xff0000,%edi
sar    $0x10,%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
mov    -0x8(%rbp),%edi
and    $0xff00,%edi
sar    $0x8,%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
mov    -0x8(%rbp),%edi
and    $0xff,%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
jmp    117c <main+0x4c>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x2ea3(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11ec <main+0xbc>
mov    0x2e59(%rip),%r12
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
shr    $0x18,%eax
mov    (%r12),%esi
mov    %eax,%edi
call   1050 <putc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
mov    (%r12),%esi
call   1050 <putc@plt>
movzbl %bh,%edi
mov    (%r12),%esi
call   1050 <putc@plt>
movzbl %bl,%edi
mov    (%r12),%esi
call   1050 <putc@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %ebx,%rbx
add    %rax,%rbx
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <main+0x60>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 1024, i32 %5)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i64 @strlen(i8* %7)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = add nsw i64 %10, %8
%12 = trunc i64 %11 to i32
store i32 %12, i32* %2
br label %13
13: ; preds = %18, %0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32* @fgets(i8* %14, i32 1024, i32 %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %44
18: ; preds = %13
%19 = load i32, i32* %2
%20 = and i32 %19, -16777216
%21 = lshr i32 %20, 24
%22 = load i32, i32* @stdout
%23 = call i32 @putc(i32 %21, i32 %22)
%24 = load i32, i32* %2
%25 = and i32 %24, 16711680
%26 = ashr i32 %25, 16
%27 = load i32, i32* @stdout
%28 = call i32 @putc(i32 %26, i32 %27)
%29 = load i32, i32* %2
%30 = and i32 %29, 65280
%31 = ashr i32 %30, 8
%32 = load i32, i32* @stdout
%33 = call i32 @putc(i32 %31, i32 %32)
%34 = load i32, i32* %2
%35 = and i32 %34, 255
%36 = load i32, i32* @stdout
%37 = call i32 @putc(i32 %35, i32 %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %2
br label %13
44: ; preds = %13
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 1024, i32 %3)
%5 = call i64 @strlen(i8* %2)
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %2, i32 1024, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %33, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %29, %9 ], [ %5, %0 ]
%11 = trunc i64 %10 to i32
%12 = lshr i32 %11, 24
%13 = load i32, i32* @stdout
%14 = call i32 @putc(i32 %12, i32 %13)
%15 = lshr i32 %11, 16
%16 = and i32 %15, 255
%17 = load i32, i32* @stdout
%18 = call i32 @putc(i32 %16, i32 %17)
%19 = lshr i32 %11, 8
%20 = and i32 %19, 255
%21 = load i32, i32* @stdout
%22 = call i32 @putc(i32 %20, i32 %21)
%23 = and i32 %11, 255
%24 = load i32, i32* @stdout
%25 = call i32 @putc(i32 %23, i32 %24)
%26 = call i64 @strlen(i8* %2)
%27 = shl i64 %10, 32
%28 = ashr exact i64 %27, 32
%29 = add nsw i64 %26, %28
%30 = load i32, i32* @stdin
%31 = call i32* @fgets(i8* %2, i32 1024, i32 %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %9
33: ; preds = %9, %0
ret i32 0
}