#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 LOCK_EX;
int LOCK_NB;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int flock(int, int);
int open(char const *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  const char *pathname = "/tmp/file1";
  int flags = O_WRONLY | O_CREAT;
  int fd = open(pathname, flags);
  perror("open");
  int operation = LOCK_EX | LOCK_NB;
  int ret = flock(fd, operation);
  perror("flock");
  sleep(60 * 60 * 24);
  close(fd);
  perror("close");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    0x2e7e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    0x2e16(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <flock@plt>
mov    %eax,-0x20(%rbp)
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x15180,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
lea    0xe34(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe96(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ebx
lea    0xe93(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e5c(%rip),%rax
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %ebx,%edi
call   1060 <flock@plt>
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
mov    $0x15180,%edi
call   1070 <sleep@plt>
mov    %ebx,%edi
call   1030 <close@plt>
lea    0xe5c(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/tmp/file1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [5 x i8] c"open\00"
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@.str.2 = [6 x i8] c"flock\00"
@.str.3 = [6 x i8] c"close\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
store i32 %9, i32* %3
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %4
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @LOCK_EX
%15 = load i32, i32* @LOCK_NB
%16 = or i32 %14, %15
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = call i32 @flock(i32 %17, i32 %18)
store i32 %19, i32* %6
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @sleep(i32 86400)
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/tmp/file1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [5 x i8] c"open\00"
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@.str.2 = [6 x i8] c"flock\00"
@.str.3 = [6 x i8] c"close\00"
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @LOCK_EX
%7 = load i32, i32* @LOCK_NB
%8 = or i32 %7, %6
%9 = tail call i32 @flock(i32 %4, i32 %8)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @sleep(i32 86400)
%12 = tail call i32 @close(i32 %4)
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}