#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 int64_t;

/* Variables and functions */
int EOF;
int atoi(char const *const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getchar();
int /*<<< orphan*/ stderr;
int main(int n_arg, char const *const *arg) {
  int64_t data_count;
  int c = 0;
  if ((n_arg != 2) || ((data_count = atoi(arg[1])) < 0)) {
    fprintf(stderr, "usage: check_ramp number-of-kilobytes\n");
    return 1;
  }
  data_count *= 1024;
  while (data_count--) {
    if (getchar() != c) {
      fprintf(stderr, "error in standard input\n");
      return 1;
    }
    if (c == 255) {
      c = 0;
    } else {
      ++c;
    }
  }
  if (getchar() != EOF) {
    fprintf(stderr, "error in standard input (too long)\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1170 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1191 <main+0x61>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1244 <main+0x114>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1206 <main+0xd6>
mov    $0x0,%al
call   1030 <getchar@plt>
cmp    -0x18(%rbp),%eax
je     11df <main+0xaf>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1244 <main+0x114>
cmpl   $0xff,-0x18(%rbp)
jne    11f8 <main+0xc8>
movl   $0x0,-0x18(%rbp)
jmp    1201 <main+0xd1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119a <main+0x6a>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
je     123d <main+0x10d>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1244 <main+0x114>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%r14
cmp    $0x2,%edi
jne    11a9 <main+0x79>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
js     11a9 <main+0x79>
je     118e <main+0x5e>
mov    %eax,%ebp
shl    $0xa,%ebp
neg    %ebp
xor    %r15d,%r15d
lea    0xec4(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    %ebx,%eax
jne    11a9 <main+0x79>
cmp    $0xff,%ebx
lea    0x1(%rbx),%eax
cmove  %r15d,%eax
mov    %eax,%ebx
inc    %ebp
jne    1170 <main+0x40>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
je     11bf <main+0x8f>
lea    0xe97(%rip),%r14
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"usage: check_ramp number-of-kilobytes\0A\00"
@.str.1 = [25 x i8] c"error in standard input\0A\00"
@EOF = global i32 0
@.str.2 = [36 x i8] c"error in standard input (too long)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10, %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %49
19: ; preds = %10
%20 = load i32, i32* %6
%21 = mul nsw i32 %20, 1024
store i32 %21, i32* %6
br label %22
22: ; preds = %40, %19
%23 = load i32, i32* %6
%24 = add nsw i32 %23, -1
store i32 %24, i32* %6
%25 = icmp ne i32 %23, 0
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = call i32 (...) @getchar()
%28 = load i32, i32* %7
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %49
33: ; preds = %26
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, 255
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 0, i32* %7
br label %40
37: ; preds = %33
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %40
40: ; preds = %37, %36
br label %22
41: ; preds = %22
%42 = call i32 (...) @getchar()
%43 = load i32, i32* @EOF
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %49
48: ; preds = %41
store i32 0, i32* %3
br label %49
49: ; preds = %48, %45, %30, %16
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"usage: check_ramp number-of-kilobytes\0A\00"
@.str.1 = [25 x i8] c"error in standard input\0A\00"
@EOF = global i32 0
@.str.2 = [36 x i8] c"error in standard input (too long)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %28
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %4
%10 = icmp eq i32 %7, 0
br i1 %10, label %24, label %11
11: ; preds = %9
%12 = shl nsw i32 %7, 10
br label %13
13: ; preds = %11, %19
%14 = phi i32 [ %16, %19 ], [ %12, %11 ]
%15 = phi i32 [ %22, %19 ], [ 0, %11 ]
%16 = add nsw i32 %14, -1
%17 = tail call i32 (...) @getchar()
%18 = icmp eq i32 %17, %15
br i1 %18, label %19, label %28
19: ; preds = %13
%20 = icmp eq i32 %15, 255
%21 = add nsw i32 %15, 1
%22 = select i1 %20, i32 0, i32 %21
%23 = icmp eq i32 %16, 0
br i1 %23, label %24, label %13
24: ; preds = %19, %9
%25 = tail call i32 (...) @getchar()
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %32, label %28
28: ; preds = %13, %24, %2, %4
%29 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), %24 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %13 ]
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* %29)
br label %32
32: ; preds = %28, %24
%33 = phi i32 [ 0, %24 ], [ 1, %28 ]
ret i32 %33
}