#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 */
struct flock {
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
  int /*<<< orphan*/ l_type;
};

/* Variables and functions */
int /*<<< orphan*/ F_RDLCK;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
lectPartagee(int a) {
  struct flock verrou;
  verrou.l_type = F_RDLCK;
  verrou.l_whence = SEEK_SET;
  verrou.l_start = 0;
  verrou.l_len = 0;
  if (fcntl(a, F_SETLK, &verrou) != 0)
    printf("error");
  int lu;
  char buff[1024];
  while ((lu = read(a, buff, 1024)) != 0) {
    write(1, buff, lu);
  }
  sleep(5);
}


x86 assembly (clang, -O0):
<lectPartagee>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
je     11b1 <lectPartagee+0x61>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
jmp    11b6 <lectPartagee+0x66>
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11ef <lectPartagee+0x9f>
lea    -0x430(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    11b6 <lectPartagee+0x66>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lectPartagee>:
push   %rbp
push   %rbx
sub    $0x428,%rsp
mov    %edi,%ebp
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
test   %rax,%rax
je     119e <lectPartagee+0x4e>
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
je     11e2 <lectPartagee+0x92>
lea    0x20(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    11c0 <lectPartagee+0x70>
mov    $0x5,%edi
call   1070 <sleep@plt>
add    $0x428,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i64, i32, i32 }
@F_RDLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [6 x i8] c"error\00"
define i32 @lectPartagee(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.flock
%5 = alloca i32
%6 = alloca [1024 x i8]
store i32 %0, i32* %3
%7 = load i32, i32* @F_RDLCK
%8 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 3
store i32 %7, i32* %8
%9 = load i32, i32* @SEEK_SET
%10 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 2
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 1
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i64 0, i64* %12
%13 = load i32, i32* %3
%14 = load i32, i32* @F_SETLK
%15 = call i64 @fcntl(i32 %13, i32 %14, %struct.flock* %4)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %1
br label %20
20: ; preds = %25, %19
%21 = load i32, i32* %3
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 1024)
store i32 %23, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 @write(i32 1, i8* %26, i32 %27)
br label %20
29: ; preds = %20
%30 = call i32 @sleep(i32 5)
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i32, i32 }
@F_RDLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [6 x i8] c"error\00"
define i32 @lectPartagee(i32 %0) {
%2 = alloca %struct.flock
%3 = alloca [1024 x i8]
%4 = bitcast %struct.flock* %2 to i8*
%5 = load i32, i32* @F_RDLCK
%6 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 3
store i32 %5, i32* %6
%7 = load i32, i32* @SEEK_SET
%8 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 2
store i32 %7, i32* %8
%9 = bitcast %struct.flock* %2 to i8*
%10 = load i32, i32* @F_SETLK
%11 = call i64 @fcntl(i32 %0, i32 %10, %struct.flock* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 @read(i32 %0, i8* %16, i32 1024)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15, %19
%20 = phi i32 [ %22, %19 ], [ %17, %15 ]
%21 = call i32 @write(i32 1, i8* %16, i32 %20)
%22 = call i32 @read(i32 %0, i8* %16, i32 1024)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %19
24: ; preds = %19, %15
%25 = call i32 @sleep(i32 5)
ret i32 undef
}