#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
char *malloc(size_t);
char *realloc(char *, size_t);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  setlocale(LC_CTYPE, "en_US.UTF-8");
  if (argc != 2) {
    fprintf(stderr, "Usage: %s file_name\n", argv[0]);
    return -1;
  }
  const char *filename = argv[1];
  FILE *myfile = fopen(filename, "r");
  if (!myfile) {
    fprintf(stderr, "Could not open file %s \n", filename);
    return -1;
  }
  size_t buf1_size = 1024;
  size_t buf2_size = 1024;
  char *buf1 = malloc(buf1_size);
  ssize_t read;
  read = getline(&buf1, &buf1_size, myfile);
  if (read <= 0) {
    fprintf(stderr, "The file %s seems to be empty \n", filename);
    return -1;
  }
  if (buf2_size < buf1_size) {
    buf2_size = buf1_size;
  }
  char *buf2 = malloc(buf2_size);
  strcpy(buf2, buf1);
  while ((read = getline(&buf1, &buf1_size, myfile)) > 0) {
    if (strcmp(buf1, buf2) <= 0) {
      fprintf(stderr, "Failed here: \n %s and %s\n", buf1, buf2);
      return -1;
    } else {
      if (buf2_size < buf1_size) {
        buf2_size = buf1_size;
        buf2 = realloc(buf2, buf2_size);
      }
      strcpy(buf2, buf1);
    }
  }
  fprintf(stdout, "Success\n");
  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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1080 <setlocale@plt>
cmpl   $0x2,-0x8(%rbp)
je     11df <main+0x5f>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1231 <main+0xb1>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <main+0x1fd>
movq   $0x400,-0x28(%rbp)
movq   $0x400,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <getline@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jg     1295 <main+0x115>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    12ab <main+0x12b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <getline@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jle    135f <main+0x1df>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jg     1326 <main+0x1a6>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137d <main+0x1fd>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    134d <main+0x1cd>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <realloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12c5 <main+0x145>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1080 <setlocale@plt>
cmp    $0x2,%ebp
jne    12b3 <main+0x133>
mov    0x8(%rbx),%rbx
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c8 <main+0x148>
mov    %rax,%r14
movq   $0x400,0x10(%rsp)
mov    $0x400,%r15d
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    12f5 <main+0x175>
mov    0x10(%rsp),%rax
cmp    $0x401,%rax
cmovae %rax,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    12da <main+0x15a>
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    1280 <main+0x100>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    12da <main+0x15a>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jle    1325 <main+0x1a5>
mov    0x10(%rsp),%rbp
cmp    %rbp,%r15
jae    1260 <main+0xe0>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    %rbp,%r15
jmp    1260 <main+0xe0>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd46(%rip),%rsi
jmp    1308 <main+0x188>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
jmp    1305 <main+0x185>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1314 <main+0x194>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xd22(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    130f <main+0x18f>

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [12 x i8] c"en_US.UTF-8\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Usage: %s file_name\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Could not open file %s \0A\00"
@.str.4 = [32 x i8] c"The file %s seems to be empty \0A\00"
@.str.5 = [26 x i8] c"Failed here: \0A %s and %s\0A\00"
@stdout = global i32 0
@.str.6 = [9 x i8] c"Success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @LC_CTYPE
%14 = call i32 @setlocale(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %89
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %6
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %33)
store i32 -1, i32* %3
br label %89
35: ; preds = %23
store i64 1024, i64* %8
store i64 1024, i64* %9
%36 = load i64, i64* %8
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %10
%38 = load i32*, i32** %7
%39 = call i64 @getline(i8** %10, i64* %8, i32* %38)
store i64 %39, i64* %11
%40 = load i64, i64* %11
%41 = icmp sle i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %6
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %44)
store i32 -1, i32* %3
br label %89
46: ; preds = %35
%47 = load i64, i64* %9
%48 = load i64, i64* %8
%49 = icmp ult i64 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i64, i64* %8
store i64 %51, i64* %9
br label %52
52: ; preds = %50, %46
%53 = load i64, i64* %9
%54 = call i8* @malloc(i64 %53)
store i8* %54, i8** %12
%55 = load i8*, i8** %12
%56 = load i8*, i8** %10
%57 = call i32 @strcpy(i8* %55, i8* %56)
br label %58
58: ; preds = %85, %52
%59 = load i32*, i32** %7
%60 = call i64 @getline(i8** %10, i64* %8, i32* %59)
store i64 %60, i64* %11
%61 = icmp sgt i64 %60, 0
br i1 %61, label %62, label %86
62: ; preds = %58
%63 = load i8*, i8** %10
%64 = load i8*, i8** %12
%65 = call i64 @strcmp(i8* %63, i8* %64)
%66 = icmp sle i64 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %10
%70 = load i8*, i8** %12
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %69, i8* %70)
store i32 -1, i32* %3
br label %89
72: ; preds = %62
%73 = load i64, i64* %9
%74 = load i64, i64* %8
%75 = icmp ult i64 %73, %74
br i1 %75, label %76, label %81
76: ; preds = %72
%77 = load i64, i64* %8
store i64 %77, i64* %9
%78 = load i8*, i8** %12
%79 = load i64, i64* %9
%80 = call i8* @realloc(i8* %78, i64 %79)
store i8* %80, i8** %12
br label %81
81: ; preds = %76, %72
%82 = load i8*, i8** %12
%83 = load i8*, i8** %10
%84 = call i32 @strcpy(i8* %82, i8* %83)
br label %85
85: ; preds = %81
br label %58
86: ; preds = %58
%87 = load i32, i32* @stdout
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %89
89: ; preds = %86, %67, %42, %31, %17
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [12 x i8] c"en_US.UTF-8\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Usage: %s file_name\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Could not open file %s \0A\00"
@.str.4 = [32 x i8] c"The file %s seems to be empty \0A\00"
@.str.5 = [26 x i8] c"Failed here: \0A %s and %s\0A\00"
@stdout = global i32 0
@.str.6 = [9 x i8] c"Success\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = load i32, i32* @LC_CTYPE
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %65
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %65
20: ; preds = %12
%21 = bitcast i64* %3 to i8*
store i64 1024, i64* %3
%22 = bitcast i8** %4 to i8*
%23 = tail call dereferenceable_or_null(1024) i8* @malloc(i64 1024)
store i8* %23, i8** %4
%24 = call i64 @getline(i8** %4, i64* %3, i32* %15)
%25 = icmp slt i64 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %63
29: ; preds = %20
%30 = load i64, i64* %3
%31 = icmp ugt i64 %30, 1024
%32 = select i1 %31, i64 %30, i64 1024
%33 = call i8* @malloc(i64 %32)
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = call i64 @getline(i8** %4, i64* %3, i32* %15)
%37 = icmp sgt i64 %36, 0
br i1 %37, label %38, label %60
38: ; preds = %29, %53
%39 = phi i8* [ %55, %53 ], [ %33, %29 ]
%40 = phi i64 [ %54, %53 ], [ %32, %29 ]
%41 = load i8*, i8** %4
%42 = call i64 @strcmp(i8* %41, i8* %39)
%43 = icmp slt i64 %42, 1
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %4
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %46, i8* %39)
br label %63
48: ; preds = %38
%49 = load i64, i64* %3
%50 = icmp ult i64 %40, %49
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i8* @realloc(i8* %39, i64 %49)
br label %53
53: ; preds = %51, %48
%54 = phi i64 [ %49, %51 ], [ %40, %48 ]
%55 = phi i8* [ %52, %51 ], [ %39, %48 ]
%56 = load i8*, i8** %4
%57 = call i32 @strcpy(i8* %55, i8* %56)
%58 = call i64 @getline(i8** %4, i64* %3, i32* %15)
%59 = icmp sgt i64 %58, 0
br i1 %59, label %38, label %60
60: ; preds = %53, %29
%61 = load i32, i32* @stdout
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %44, %60, %26
%64 = phi i32 [ -1, %26 ], [ -1, %44 ], [ 0, %60 ]
br label %65
65: ; preds = %17, %63, %8
%66 = phi i32 [ -1, %8 ], [ %64, %63 ], [ -1, %17 ]
ret i32 %66
}