#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_SETLK;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
lectExclu(int a) {
  struct flock verrou;
  verrou.l_type = F_WRLCK;
  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);
  }
}


x86 assembly (clang, -O0):
<lectExclu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
je     11a1 <lectExclu+0x61>
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
jmp    11a6 <lectExclu+0x66>
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11df <lectExclu+0x9f>
lea    -0x430(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    11a6 <lectExclu+0x66>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lectExclu>:
push   %rbp
push   %rbx
sub    $0x428,%rsp
mov    %edi,%ebp
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
test   %rax,%rax
je     118e <lectExclu+0x4e>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
je     11d2 <lectExclu+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    11b0 <lectExclu+0x70>
add    $0x428,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i64, i32, i32 }
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [6 x i8] c"error\00"
define i32 @lectExclu(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_WRLCK
%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 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i32, i32 }
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [6 x i8] c"error\00"
define i32 @lectExclu(i32 %0) {
%2 = alloca %struct.flock
%3 = alloca [1024 x i8]
%4 = bitcast %struct.flock* %2 to i8*
%5 = load i32, i32* @F_WRLCK
%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
ret i32 undef
}