#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 {
  void *l_type;
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
};
typedef int pid_t;
typedef int /*<<< orphan*/ lock;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ F_SETLKW;
void *F_UNLCK;
void *F_WRLCK;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, struct flock *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ memset(struct flock *, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd;
  pid_t pid;
  struct flock lock;
  memset(&lock, 0x00, sizeof(lock));
  lock.l_type = F_WRLCK;
  lock.l_whence = SEEK_SET;
  lock.l_start = 0;
  lock.l_len = 0;
  fd = open("test.txt", O_WRONLY);
  if (fd == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day05/shared.c",
              30, "open", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if ((pid = fork()) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day05/shared.c",
              33, "fork", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (pid > 0) {
    lock.l_type = F_WRLCK;
    if (fcntl(fd, F_SETLKW, &lock) == -1)
      do {
        fprintf(stderr, "[%s][%d]:%s %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/"
                "heads/master/apue/day05/shared.c",
                38, "fcntl", strerror(errno));
        exit(EXIT_FAILURE);
      } while (0);
    write(fd, "parent", 6);
    lock.l_type = F_UNLCK;
    if (fcntl(fd, F_SETLKW, &lock) == -1)
      do {
        fprintf(stderr, "[%s][%d]:%s %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/"
                "heads/master/apue/day05/shared.c",
                42, "fcntl", strerror(errno));
        exit(EXIT_FAILURE);
      } while (0);
  } else {
    lock.l_type = F_WRLCK;
    if (fcntl(fd, F_SETLKW, &lock) == -1)
      do {
        fprintf(stderr, "[%s][%d]:%s %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/"
                "heads/master/apue/day05/shared.c",
                47, "fcntl", strerror(errno));
        exit(EXIT_FAILURE);
      } while (0);
    write(fd, "child", 5);
    lock.l_type = F_UNLCK;
    if (fcntl(fd, F_SETLKW, &lock) == -1)
      do {
        fprintf(stderr, "[%s][%d]:%s %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/"
                "heads/master/apue/day05/shared.c",
                51, "fcntl", strerror(errno));
        exit(EXIT_FAILURE);
      } while (0);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xe17(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    124d <main+0xbd>
jmp    1200 <main+0x70>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%r9
lea    0xde2(%rip),%rsi
lea    0xdeb(%rip),%rdx
mov    $0x1e,%ecx
lea    0xe74(%rip),%r8
call   1070 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12b2 <main+0x122>
jmp    1265 <main+0xd5>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%r9
lea    0xd7d(%rip),%rsi
lea    0xd86(%rip),%rdx
mov    $0x21,%ecx
lea    0xe14(%rip),%r8
call   1070 <fprintf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jle    13d1 <main+0x241>
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    133a <main+0x1aa>
jmp    12ed <main+0x15d>
mov    0x2cdc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%r9
lea    0xcf5(%rip),%rsi
lea    0xcfe(%rip),%rdx
mov    $0x26,%ecx
lea    0xd91(%rip),%r8
call   1070 <fprintf@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xd7a(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    13cc <main+0x23c>
jmp    137f <main+0x1ef>
mov    0x2c4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c36(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%r9
lea    0xc63(%rip),%rsi
lea    0xc6c(%rip),%rdx
mov    $0x2a,%ecx
lea    0xcff(%rip),%r8
call   1070 <fprintf@plt>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    14e6 <main+0x356>
mov    0x2bd8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2bff(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    144f <main+0x2bf>
jmp    1402 <main+0x272>
mov    0x2bc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%r9
lea    0xbe0(%rip),%rsi
lea    0xbe9(%rip),%rdx
mov    $0x2f,%ecx
lea    0xc7c(%rip),%r8
call   1070 <fprintf@plt>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xc6c(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    0x2b76(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2b6d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    14e1 <main+0x351>
jmp    1494 <main+0x304>
mov    0x2b35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2b21(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%r9
lea    0xb4e(%rip),%rsi
lea    0xb57(%rip),%rdx
mov    $0x33,%ecx
lea    0xbea(%rip),%r8
call   1070 <fprintf@plt>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    14e6 <main+0x356>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e02(%rip),%r14
mov    (%r14),%rax
mov    %rax,(%rsp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12e1 <main+0x151>
mov    %eax,%ebx
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     1319 <main+0x189>
mov    %eax,%ebp
mov    (%r14),%rax
mov    %rax,(%rsp)
mov    0x2dde(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <fcntl@plt>
test   %ebp,%ebp
jle    128f <main+0xff>
cmp    $0xffffffff,%eax
je     1351 <main+0x1c1>
lea    0xe93(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    (%r14),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    12cf <main+0x13f>
mov    0x2d72(%rip),%rax
mov    (%rax),%ebx
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd94(%rip),%rsi
lea    0xd9d(%rip),%rdx
lea    0xe35(%rip),%r8
mov    %ebx,%edi
mov    $0x2a,%ecx
jmp    13ee <main+0x25e>
cmp    $0xffffffff,%eax
je     1386 <main+0x1f6>
lea    0xe26(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    (%r14),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     13bb <main+0x22b>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2ce8(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd0a(%rip),%rsi
lea    0xd13(%rip),%rdx
lea    0xda1(%rip),%r8
mov    %ebx,%edi
mov    $0x1e,%ecx
jmp    13ee <main+0x25e>
mov    0x2cb0(%rip),%rax
mov    (%rax),%ebx
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcd2(%rip),%rsi
lea    0xcdb(%rip),%rdx
lea    0xd6e(%rip),%r8
mov    %ebx,%edi
mov    $0x21,%ecx
jmp    13ee <main+0x25e>
mov    0x2c78(%rip),%rax
mov    (%rax),%ebx
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc9a(%rip),%rsi
lea    0xca3(%rip),%rdx
lea    0xd3b(%rip),%r8
mov    %ebx,%edi
mov    $0x26,%ecx
jmp    13ee <main+0x25e>
mov    0x2c43(%rip),%rax
mov    (%rax),%ebx
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc65(%rip),%rsi
lea    0xc6e(%rip),%rdx
lea    0xd06(%rip),%r8
mov    %ebx,%edi
mov    $0x2f,%ecx
jmp    13ee <main+0x25e>
mov    0x2c0e(%rip),%rax
mov    (%rax),%ebx
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc30(%rip),%rsi
lea    0xc39(%rip),%rdx
lea    0xcd1(%rip),%r8
mov    %ebx,%edi
mov    $0x33,%ecx
mov    %rax,%r9
call   1070 <fprintf@plt>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.flock = type { i8*, i64, i64, i32 }
@F_WRLCK = global i8* null
@SEEK_SET = global i32 0
@.str = [9 x i8] c"test.txt\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day05/shared.c\00"
@.str.3 = [5 x i8] c"open\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [5 x i8] c"fork\00"
@F_SETLKW = global i32 0
@.str.5 = [6 x i8] c"fcntl\00"
@.str.6 = [7 x i8] c"parent\00"
@F_UNLCK = global i8* null
@.str.7 = [6 x i8] c"child\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.flock
store i32 0, i32* %1
%5 = call i32 @memset(%struct.flock* %4, i32 0, i32 32)
%6 = load i8*, i8** @F_WRLCK
%7 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i8* %6, i8** %7
%8 = load i32, i32* @SEEK_SET
%9 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 3
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 2
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 1
store i64 0, i64* %11
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %25
16: ; preds = %0
br label %17
17: ; preds = %16
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; No predecessors!
br label %25
25: ; preds = %24, %0
%26 = call i32 (...) @fork()
store i32 %26, i32* %3
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %37
28: ; preds = %25
br label %29
29: ; preds = %28
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; No predecessors!
br label %37
37: ; preds = %36, %25
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %75
40: ; preds = %37
%41 = load i8*, i8** @F_WRLCK
%42 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i8* %41, i8** %42
%43 = load i32, i32* %2
%44 = load i32, i32* @F_SETLKW
%45 = call i32 @fcntl(i32 %43, i32 %44, %struct.flock* %4)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %56
47: ; preds = %40
br label %48
48: ; preds = %47
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %40
%57 = load i32, i32* %2
%58 = call i32 @write(i32 %57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%59 = load i8*, i8** @F_UNLCK
%60 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i8* %59, i8** %60
%61 = load i32, i32* %2
%62 = load i32, i32* @F_SETLKW
%63 = call i32 @fcntl(i32 %61, i32 %62, %struct.flock* %4)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %74
65: ; preds = %56
br label %66
66: ; preds = %65
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; No predecessors!
br label %74
74: ; preds = %73, %56
br label %110
75: ; preds = %37
%76 = load i8*, i8** @F_WRLCK
%77 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i8* %76, i8** %77
%78 = load i32, i32* %2
%79 = load i32, i32* @F_SETLKW
%80 = call i32 @fcntl(i32 %78, i32 %79, %struct.flock* %4)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %91
82: ; preds = %75
br label %83
83: ; preds = %82
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %86)
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; No predecessors!
br label %91
91: ; preds = %90, %75
%92 = load i32, i32* %2
%93 = call i32 @write(i32 %92, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 5)
%94 = load i8*, i8** @F_UNLCK
%95 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i8* %94, i8** %95
%96 = load i32, i32* %2
%97 = load i32, i32* @F_SETLKW
%98 = call i32 @fcntl(i32 %96, i32 %97, %struct.flock* %4)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %109
100: ; preds = %91
br label %101
101: ; preds = %100
%102 = load i32, i32* @stderr
%103 = load i32, i32* @errno
%104 = call i8* @strerror(i32 %103)
%105 = call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %104)
%106 = load i32, i32* @EXIT_FAILURE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; No predecessors!
br label %109
109: ; preds = %108, %91
br label %110
110: ; preds = %109, %74
%111 = load i32, i32* %2
%112 = call i32 @close(i32 %111)
ret i32 0
}

LLVM IR (-O2):
%struct.flock = type { i8*, i64, i64, i32 }
@F_WRLCK = global i8* null
@SEEK_SET = global i32 0
@.str = [9 x i8] c"test.txt\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day05/shared.c\00"
@.str.3 = [5 x i8] c"open\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [5 x i8] c"fork\00"
@F_SETLKW = global i32 0
@.str.5 = [6 x i8] c"fcntl\00"
@.str.6 = [7 x i8] c"parent\00"
@F_UNLCK = global i8* null
@.str.7 = [6 x i8] c"child\00"
define i32 @main() {
%1 = alloca %struct.flock
%2 = bitcast %struct.flock* %1 to i8*
%3 = call i32 @memset(%struct.flock* %1, i32 0, i32 32)
%4 = load i8*, i8** @F_WRLCK
%5 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 0
store i8* %4, i8** %5
%6 = load i32, i32* @SEEK_SET
%7 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 3
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 1
%9 = bitcast i64* %8 to i8*
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %0
%21 = call i32 (...) @fork()
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = icmp sgt i32 %21, 0
%32 = load i8*, i8** @F_WRLCK
store i8* %32, i8** %5
%33 = load i32, i32* @F_SETLKW
%34 = call i32 @fcntl(i32 %11, i32 %33, %struct.flock* %1)
%35 = icmp eq i32 %34, -1
br i1 %31, label %36, label %57
36: ; preds = %30
br i1 %35, label %37, label %44
37: ; preds = %36
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %36
%45 = call i32 @write(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%46 = load i8*, i8** @F_UNLCK
store i8* %46, i8** %5
%47 = load i32, i32* @F_SETLKW
%48 = call i32 @fcntl(i32 %11, i32 %47, %struct.flock* %1)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %78
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %30
br i1 %35, label %58, label %65
58: ; preds = %57
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %57
%66 = call i32 @write(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 5)
%67 = load i8*, i8** @F_UNLCK
store i8* %67, i8** %5
%68 = load i32, i32* @F_SETLKW
%69 = call i32 @fcntl(i32 %11, i32 %68, %struct.flock* %1)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %78
71: ; preds = %65
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.2, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %74)
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %65, %44
%79 = call i32 @close(i32 %11)
ret i32 0
}