#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int rand();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  FILE *fp;
  int data[50], val, j;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fp = fopen(argv[1], "w")) == NULL) {
    fprintf(stderr, "Err. fopen(), %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < 50; i++) {
    val = rand() % 1000;
    fprintf(fp, "%2d %3d\n", i, val);
  }
  fclose(fp);
  if ((fp = fopen(argv[1], "r+")) == NULL) {
    fprintf(stderr, "Err. fopen(), %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  for (int i = 1; i <= 50; i++) {
    fscanf(fp, "%2d %3d", &j, &val);
    *(data + 50 - i) = val;
  }
  fprintf(fp, "\n-----[ Array elements inversion ]-----\n");
  for (int i = 1; i <= 50; i++) {
    fprintf(fp, "%2d %3d\n", i, *(data + i - 1));
  }
  fclose(fp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c0 <main+0x50>
mov    0x2e46(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1227 <main+0xb7>
mov    0x2df7(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x100(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x100(%rbp),%rdi
mov    %rax,%rdx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0xec(%rbp)
cmpl   $0x32,-0xec(%rbp)
jge    1285 <main+0x115>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0xe4(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xec(%rbp),%edx
mov    -0xe4(%rbp),%ecx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xec(%rbp)
jmp    1231 <main+0xc1>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12f5 <main+0x185>
mov    0x2d29(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x108(%rbp)
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x108(%rbp),%rdi
mov    %rax,%rdx
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x1,-0xf0(%rbp)
cmpl   $0x32,-0xf0(%rbp)
jg     1354 <main+0x1e4>
mov    -0x18(%rbp),%rdi
lea    0xd1f(%rip),%rsi
lea    -0xe8(%rbp),%rdx
lea    -0xe4(%rbp),%rcx
call   1040 <fscanf@plt>
mov    -0xe4(%rbp),%ecx
movslq -0xf0(%rbp),%rdx
xor    %eax,%eax
sub    %rdx,%rax
mov    %ecx,-0x18(%rbp,%rax,4)
mov    -0xf0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf0(%rbp)
jmp    12ff <main+0x18f>
mov    -0x18(%rbp),%rdi
lea    0xcdf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0xf4(%rbp)
cmpl   $0x32,-0xf4(%rbp)
jg     13b7 <main+0x247>
mov    -0x18(%rbp),%rdi
mov    -0xf4(%rbp),%edx
movslq -0xf4(%rbp),%rax
mov    -0xe4(%rbp,%rax,4),%ecx
lea    0xc8e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4(%rbp)
jmp    1370 <main+0x200>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe0,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12f5 <main+0x175>
mov    0x8(%r14),%rdi
lea    0xe70(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12ce <main+0x14e>
mov    %rax,%r12
lea    0xe6c(%rip),%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%rbx
imul   $0x10624dd3,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%ebx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x32,%ebp
jne    11c0 <main+0x40>
mov    %ebx,0x8(%rsp)
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x8(%r14),%rdi
lea    0xe1d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12ce <main+0x14e>
mov    %rax,%rbx
mov    $0x31,%ebp
lea    0xe03(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1040 <fscanf@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rsp,%rbp,4)
add    $0xffffffffffffffff,%rbp
jb     1240 <main+0xc0>
lea    0xdd8(%rip),%rdi
mov    $0x28,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xdab(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbp,4),%ecx
add    $0x1,%rbp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x32,%rbp
jne    1290 <main+0x110>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0b(%rip),%rax
movslq (%rax),%rbx
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd2b(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
jmp    1309 <main+0x189>
mov    0x2ce4(%rip),%rax
movslq (%rax),%rdi
mov    (%r14),%rdx
lea    0xcf7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [18 x i8] c"Err. fopen(), %s\0A\00"
@errno = global i32 0
@.str.3 = [9 x i8] c"%2d %3d\0A\00"
@.str.4 = [3 x i8] c"r+\00"
@.str.5 = [8 x i8] c"%2d %3d\00"
@.str.6 = [41 x i8] c"\0A-----[ Array elements inversion ]-----\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [50 x i32]
%8 = alloca i32
%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 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
%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 ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i32*
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %25
store i32 0, i32* %10
br label %41
41: ; preds = %51, %40
%42 = load i32, i32* %10
%43 = icmp slt i32 %42, 50
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = call i32 (...) @rand()
%46 = srem i32 %45, 1000
store i32 %46, i32* %8
%47 = load i32*, i32** %6
%48 = load i32, i32* %10
%49 = load i32, i32* %8
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %41
54: ; preds = %41
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %60, i32** %6
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %71
62: ; preds = %54
%63 = load i32, i32* @stderr
%64 = sext i32 %63 to i64
%65 = inttoptr i64 %64 to i32*
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %54
store i32 1, i32* %11
br label %72
72: ; preds = %85, %71
%73 = load i32, i32* %11
%74 = icmp sle i32 %73, 50
br i1 %74, label %75, label %88
75: ; preds = %72
%76 = load i32*, i32** %6
%77 = call i32 @fscanf(i32* %76, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32* %9, i32* %8)
%78 = load i32, i32* %8
%79 = getelementptr inbounds [50 x i32], [50 x i32]* %7, i64 0, i64 0
%80 = getelementptr inbounds i32, i32* %79, i64 50
%81 = load i32, i32* %11
%82 = sext i32 %81 to i64
%83 = sub i64 0, %82
%84 = getelementptr inbounds i32, i32* %80, i64 %83
store i32 %78, i32* %84
br label %85
85: ; preds = %75
%86 = load i32, i32* %11
%87 = add nsw i32 %86, 1
store i32 %87, i32* %11
br label %72
88: ; preds = %72
%89 = load i32*, i32** %6
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %89, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %12
br label %91
91: ; preds = %104, %88
%92 = load i32, i32* %12
%93 = icmp sle i32 %92, 50
br i1 %93, label %94, label %107
94: ; preds = %91
%95 = load i32*, i32** %6
%96 = load i32, i32* %12
%97 = getelementptr inbounds [50 x i32], [50 x i32]* %7, i64 0, i64 0
%98 = load i32, i32* %12
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32, i32* %97, i64 %99
%101 = getelementptr inbounds i32, i32* %100, i64 -1
%102 = load i32, i32* %101
%103 = call i32 (i32*, i8*, ...) @fprintf(i32* %95, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %96, i32 %102)
br label %104
104: ; preds = %94
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %91
107: ; preds = %91
%108 = load i32*, i32** %6
%109 = call i32 @fclose(i32* %108)
%110 = load i32, i32* @EXIT_SUCCESS
ret i32 %110
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [18 x i8] c"Err. fopen(), %s\0A\00"
@errno = global i32 0
@.str.3 = [9 x i8] c"%2d %3d\0A\00"
@.str.4 = [3 x i8] c"r+\00"
@.str.5 = [8 x i8] c"%2d %3d\00"
@.str.6 = [41 x i8] c"\0A-----[ Array elements inversion ]-----\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [50 x i32]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %18, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = load i8*, i8** %1
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %39
store i32 %42, i32* %4
%33 = tail call i32 @fclose(i32* %21)
%34 = load i8*, i8** %19
%35 = tail call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %46, label %37
37: ; preds = %32
%38 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 50
br label %57
39: ; preds = %18, %39
%40 = phi i32 [ %44, %39 ], [ 0, %18 ]
%41 = tail call i32 (...) @rand()
%42 = srem i32 %41, 1000
%43 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %42)
%44 = add nuw nsw i32 %40, 1
%45 = icmp eq i32 %44, 50
br i1 %45, label %32, label %39
46: ; preds = %32
%47 = load i32, i32* @stderr
%48 = sext i32 %47 to i64
%49 = inttoptr i64 %48 to i32*
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = tail call i32 @exit(i32 %53)
unreachable
55: ; preds = %57
%56 = call i64 @fwrite(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i64 40, i64 1, i32* %35)
br label %68
57: ; preds = %37, %57
%58 = phi i64 [ 1, %37 ], [ %63, %57 ]
%59 = call i32 @fscanf(i32* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32* %5, i32* %4)
%60 = load i32, i32* %4
%61 = sub nsw i64 0, %58
%62 = getelementptr inbounds i32, i32* %38, i64 %61
store i32 %60, i32* %62
%63 = add nuw nsw i64 %58, 1
%64 = icmp eq i64 %63, 51
br i1 %64, label %55, label %57
65: ; preds = %68
%66 = call i32 @fclose(i32* %35)
%67 = load i32, i32* @EXIT_SUCCESS
ret i32 %67
68: ; preds = %55, %68
%69 = phi i64 [ 1, %55 ], [ %75, %68 ]
%70 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %69
%71 = getelementptr inbounds i32, i32* %70, i64 -1
%72 = load i32, i32* %71
%73 = trunc i64 %69 to i32
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %73, i32 %72)
%75 = add nuw nsw i64 %69, 1
%76 = icmp eq i64 %75, 51
br i1 %76, label %65, label %68
}