#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 /*<<< orphan*/ *fopen(char *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *fp;
  int nbytes, val1, val2, i;
  int intSize = sizeof(int);
  if (argc != 2) {
    printf("Usage: ./verify <datafile>\n");
    return 0;
  }
  if (!(fp = fopen(argv[1], "r"))) {
    printf("Can't open datafile %s\n", argv[1]);
    return 0;
  }
  nbytes = fread(&val1, intSize, 1, fp);
  if (nbytes == 0) {
    printf("No data in %s\n", argv[1]);
    return 0;
  }
  i = 1;
  while (1) {
    nbytes = fread(&val2, intSize, 1, fp);
    if (nbytes == 0)
      break;
    i++;
    if (val1 > val2) {
      printf("Failed: items %u, %u: %u > %u\n", i - 1, i, val1, val2);
      return 0;
    }
    val1 = val2;
  }
  printf("Data in %s are sorted\n", argv[1]);
}


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)
movl   $0x4,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1171 <main+0x41>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <main+0x157>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <main+0x157>
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f9 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <main+0x157>
movl   $0x1,-0x28(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1227 <main+0xf7>
jmp    1271 <main+0x141>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1266 <main+0x136>
mov    -0x28(%rbp),%esi
sub    $0x1,%esi
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <main+0x157>
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1200 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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
jne    11f4 <main+0xb4>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1202 <main+0xc2>
mov    %rax,%r15
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     120f <main+0xcf>
mov    0x4(%rsp),%r12d
mov    %rsp,%rdi
mov    $0x1,%ebx
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     11e7 <main+0xa7>
mov    %rsp,%r13
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%ebp
cmp    %ebp,%r12d
jg     1232 <main+0xf2>
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
add    $0x1,%ebx
mov    %ebp,%r12d
test   %eax,%eax
jne    11c0 <main+0x80>
mov    0x8(%r14),%rsi
lea    0xe56(%rip),%rdi
jmp    121a <main+0xda>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
jmp    1221 <main+0xe1>
mov    0x8(%r14),%rsi
lea    0xdf5(%rip),%rdi
jmp    121a <main+0xda>
mov    0x8(%r14),%rsi
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x1(%rbx),%edx
lea    0xded(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1221 <main+0xe1>

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: ./verify <datafile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Can't open datafile %s\0A\00"
@.str.3 = [15 x i8] c"No data in %s\0A\00"
@.str.4 = [31 x i8] c"Failed: items %u, %u: %u > %u\0A\00"
@.str.5 = [23 x i8] c"Data in %s are sorted\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %66
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 0, i32* %3
br label %66
27: ; preds = %16
%28 = load i32, i32* %11
%29 = load i32*, i32** %6
%30 = call i32 @fread(i32* %8, i32 %28, i32 1, i32* %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 0, i32* %3
br label %66
38: ; preds = %27
store i32 1, i32* %10
br label %39
39: ; preds = %38, %59
%40 = load i32, i32* %11
%41 = load i32*, i32** %6
%42 = call i32 @fread(i32* %9, i32 %40, i32 1, i32* %41)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
br label %61
46: ; preds = %39
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %59
52: ; preds = %46
%53 = load i32, i32* %10
%54 = sub nsw i32 %53, 1
%55 = load i32, i32* %10
%56 = load i32, i32* %8
%57 = load i32, i32* %9
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %55, i32 %56, i32 %57)
store i32 0, i32* %3
br label %66
59: ; preds = %46
%60 = load i32, i32* %9
store i32 %60, i32* %8
br label %39
61: ; preds = %45
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %61, %52, %33, %22, %14
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Can't open datafile %s\0A\00"
@.str.3 = [15 x i8] c"No data in %s\0A\00"
@.str.4 = [31 x i8] c"Failed: items %u, %u: %u > %u\0A\00"
@.str.5 = [23 x i8] c"Data in %s are sorted\0A\00"
@str = [27 x i8] c"Usage: ./verify <datafile>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %42
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %42
18: ; preds = %10
%19 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %13)
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %3
%23 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %13)
%24 = icmp eq i32 %23, 0
br i1 %24, label %39, label %31
25: ; preds = %18
%26 = load i8*, i8** %11
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %42
28: ; preds = %31
%29 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %13)
%30 = icmp eq i32 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %21, %28
%32 = phi i32 [ %34, %28 ], [ 1, %21 ]
%33 = phi i32 [ %35, %28 ], [ %22, %21 ]
%34 = add nuw nsw i32 %32, 1
%35 = load i32, i32* %4
%36 = icmp sgt i32 %33, %35
br i1 %36, label %37, label %28
37: ; preds = %31
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %34, i32 %33, i32 %35)
br label %42
39: ; preds = %28, %21
%40 = load i8*, i8** %11
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %37, %25, %15, %8
ret i32 0
}