#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*/ F_WRLCK;
int /*<<< orphan*/ O_WRONLY;
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int lockfile(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *, int);
char *strerror(scalar_t__);
int main(int argc, char *argv[]) {
  int fd = open(argv[1], O_WRONLY);
  errno = 0;
  printf("%d,%s,%d", lockfile(fd, F_WRLCK), strerror(errno), fd);
  fflush(0);
  while (1) {
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e5a(%rip),%rax
movq   $0x0,(%rax)
mov    -0x14(%rbp),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1050 <lockfile@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%esi
mov    %rax,%rdx
mov    -0x14(%rbp),%ecx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
jmp    11cc <main+0x7c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e71(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <lockfile@plt>
mov    %eax,%ebp
mov    (%r14),%rdi
call   1070 <strerror@plt>
lea    0xe69(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
mov    %ebx,%ecx
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
nopw   0x0(%rax,%rax,1)
jmp    11b0 <main+0x60>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@errno = global i64 0
@.str = [9 x i8] c"%d,%s,%d\00"
@F_WRLCK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
store i64 0, i64* @errno
%12 = load i32, i32* %6
%13 = load i32, i32* @F_WRLCK
%14 = call i32 @lockfile(i32 %12, i32 %13)
%15 = load i64, i64* @errno
%16 = call i8* @strerror(i64 %15)
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %16, i32 %17)
%19 = call i32 @fflush(i32 0)
br label %20
20: ; preds = %2, %20
br label %20
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@errno = global i64 0
@.str = [9 x i8] c"%d,%s,%d\00"
@F_WRLCK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* %4, i32 %5)
store i64 0, i64* @errno
%7 = load i32, i32* @F_WRLCK
%8 = tail call i32 @lockfile(i32 %6, i32 %7)
%9 = load i64, i64* @errno
%10 = tail call i8* @strerror(i64 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %10, i32 %6)
%12 = tail call i32 @fflush(i32 0)
br label %13
13: ; preds = %13, %2
br label %13
}