#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*/ SEEK_SET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
scalar_t__ read(int, int *, int);
int /*<<< orphan*/ stderr;
scalar_t__ write(int, int *, int);
void child(int fd, int j) {
  int v1, v2;
  lseek(fd, j * sizeof(int), SEEK_SET);
  if (read(fd, &v1, sizeof(int)) < 0 || read(fd, &v2, sizeof(int)) < 0) {
    fprintf(stderr, "Errore lettura file per ordinamento.\n");
    return;
  }
  if (v1 > v2) {
    lseek(fd, j * sizeof(int), SEEK_SET);
    if (write(fd, &v2, sizeof(int)) < 0 || write(fd, &v1, sizeof(int)) < 0) {
      fprintf(stderr, "Errore scrittura file per ordinamento.\n");
      return;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jl     119f <child+0x5f>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jge    11b9 <child+0x79>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1060 <fprintf@plt>
jmp    123a <child+0xfa>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1235 <child+0xf5>
mov    -0x4(%rbp),%edi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jl     1216 <child+0xd6>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1230 <child+0xf0>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1060 <fprintf@plt>
jmp    123a <child+0xfa>
jmp    1235 <child+0xf5>
jmp    123a <child+0xfa>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
shl    $0x2,%ebp
mov    0x2e83(%rip),%r15
mov    (%r15),%edx
mov    %ebp,%esi
call   1040 <lseek@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
lea    0xe89(%rip),%r14
test   %rax,%rax
js     11e1 <child+0xa1>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %rax,%rax
js     11e1 <child+0xa1>
mov    0x4(%rsp),%eax
cmp    (%rsp),%eax
jle    11d6 <child+0x96>
mov    (%r15),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xe6b(%rip),%r14
test   %rax,%rax
js     11e1 <child+0xa1>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %rax,%rax
js     11e1 <child+0xa1>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Errore lettura file per ordinamento.\0A\00"
@.str.1 = [40 x i8] c"Errore scrittura file per ordinamento.\0A\00"
define void @child(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %7, i32 %11, i32 %12)
%14 = load i32, i32* %3
%15 = call i64 @read(i32 %14, i32* %5, i32 4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %2
%18 = load i32, i32* %3
%19 = call i64 @read(i32 %18, i32* %6, i32 4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17, %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %48
24: ; preds = %17
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %47
28: ; preds = %24
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @lseek(i32 %29, i32 %33, i32 %34)
%36 = load i32, i32* %3
%37 = call i64 @write(i32 %36, i32* %6, i32 4)
%38 = icmp slt i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %28
%40 = load i32, i32* %3
%41 = call i64 @write(i32 %40, i32* %5, i32 4)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39, %28
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %48
46: ; preds = %39
br label %47
47: ; preds = %46, %24
br label %48
48: ; preds = %47, %43, %21
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Errore lettura file per ordinamento.\0A\00"
@.str.1 = [40 x i8] c"Errore scrittura file per ordinamento.\0A\00"
define void @child(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = shl i32 %1, 2
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %0, i32 %7, i32 %8)
%10 = call i64 @read(i32 %0, i32* %3, i32 4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %27, label %12
12: ; preds = %2
%13 = call i64 @read(i32 %0, i32* %4, i32 4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @lseek(i32 %0, i32 %7, i32 %20)
%22 = call i64 @write(i32 %0, i32* %4, i32 4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = call i64 @write(i32 %0, i32* %3, i32 4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %19, %24, %2, %12
%28 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), %12 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), %24 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), %19 ]
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* %28)
br label %31
31: ; preds = %27, %15, %24
ret void
}