#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*/ exit(int);
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) {
    fprintf(stderr, "Errore read v1.\n");
    exit(-1);
  }
  if (read(fd, &v2, sizeof(int)) < 0) {
    fprintf(stderr, "Errore read v2.\n");
    exit(-2);
  }
  if (v1 > v2) {
    lseek(fd, j * sizeof(int), SEEK_SET);
    if (write(fd, &v2, sizeof(int)) < 0) {
      fprintf(stderr, "Errore write v2.\n");
      exit(-3);
    }
    if (write(fd, &v1, sizeof(int)) < 0) {
      fprintf(stderr, "Errore write v1.\n");
      exit(-4);
    }
  }
  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    0x2e66(%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
jge    11b3 <child+0x63>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jge    11ed <child+0x9d>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    128d <child+0x13d>
mov    -0x4(%rbp),%edi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2dcb(%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
jge    124e <child+0xfe>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffd,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1288 <child+0x138>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffc,%edi
call   1070 <exit@plt>
jmp    128d <child+0x13d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
shl    $0x2,%ebp
mov    0x2e72(%rip),%r14
mov    (%r14),%edx
mov    %ebp,%esi
call   1040 <lseek@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %rax,%rax
js     11e7 <child+0x97>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %rax,%rax
js     1206 <child+0xb6>
mov    0xc(%rsp),%eax
cmp    0x8(%rsp),%eax
jle    11de <child+0x8e>
mov    (%r14),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1225 <child+0xd5>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1244 <child+0xf4>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1070 <exit@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffd,%edi
call   1070 <exit@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xfffffffc,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Errore read v1.\0A\00"
@.str.1 = [17 x i8] c"Errore read v2.\0A\00"
@.str.2 = [18 x i8] c"Errore write v2.\0A\00"
@.str.3 = [18 x i8] c"Errore write v1.\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 %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i32, i32* %3
%23 = call i64 @read(i32 %22, i32* %6, i32 4)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -2)
unreachable
29: ; preds = %21
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %57
33: ; preds = %29
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = trunc i64 %37 to i32
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @lseek(i32 %34, i32 %38, i32 %39)
%41 = load i32, i32* %3
%42 = call i64 @write(i32 %41, i32* %6, i32 4)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 -3)
unreachable
48: ; preds = %33
%49 = load i32, i32* %3
%50 = call i64 @write(i32 %49, i32* %5, i32 4)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 -4)
unreachable
56: ; preds = %48
br label %57
57: ; preds = %56, %29
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Errore read v1.\0A\00"
@.str.1 = [17 x i8] c"Errore read v2.\0A\00"
@.str.2 = [18 x i8] c"Errore write v2.\0A\00"
@.str.3 = [18 x i8] c"Errore write v1.\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 %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i64 @read(i32 %0, i32* %4, i32 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 -2)
unreachable
23: ; preds = %16
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i32, i32* @SEEK_SET
%29 = tail call i32 @lseek(i32 %0, i32 %7, i32 %28)
%30 = call i64 @write(i32 %0, i32* %4, i32 4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @exit(i32 -3)
unreachable
36: ; preds = %27
%37 = call i64 @write(i32 %0, i32* %3, i32 4)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%42 = tail call i32 @exit(i32 -4)
unreachable
43: ; preds = %36, %23
ret void
}