#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*/ GETVAL;
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ SETVAL;
int check_sem_by_id(int, int);
scalar_t__ check_sem_by_key(int);
int /*<<< orphan*/ errno;
int ftok(char *, int);
int lrand48();
int semctl(int, int, int /*<<< orphan*/, ...);
int semget(int, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_daemon();
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
int test_fn(int argc, char **argv) {
  int id, key, val;
  int ret, fail_count = 0;
  key = ftok(argv[0], 89063453);
  if (key == -1) {
    test_msg("ERR: %s:%d: "
             "Can't make key"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             115, errno, strerror(errno));
    return -1;
  }
  val = lrand48() & 0x7;
  id = semget(key, 1, 0777 | IPC_CREAT | IPC_EXCL);
  if (id == -1) {
    fail_count++;
    test_msg("ERR: %s:%d: "
             "Can't get sem"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             124, errno, strerror(errno));
    goto out;
  }
  if (semctl(id, 0, SETVAL, val) == -1) {
    fail_count++;
    test_msg("ERR: %s:%d: "
             "Can't init sem"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             129, errno, strerror(errno));
    goto out_destroy;
  }
  test_daemon();
  test_waitsig();
  ret = check_sem_by_id(id, val);
  if (ret < 0) {
    fail_count++;
    test_msg("FAIL: %s:%d: "
             "Check sem by id failed"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             139, errno, strerror(errno));
    goto out_destroy;
  }
  if (check_sem_by_key(key) < 0) {
    test_msg("FAIL: %s:%d: "
             "Check sem by key failed"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             144, errno, strerror(errno));
    fail_count++;
    goto out_destroy;
  }
  val = semctl(id, 0, GETVAL);
  if (val < 0) {
    test_msg("FAIL: %s:%d: "
             "Failed to get sem value"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             151, errno, strerror(errno));
    fail_count++;
    goto out_destroy;
  }
  if (val != 0) {
    test_msg("FAIL: %s:%d: "
             "Non-zero sem value: %d"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             156, val, errno, strerror(errno));
    fail_count++;
  }
out_destroy:
  ret = semctl(id, 1, IPC_RMID);
  if (ret < 0) {
    test_msg("FAIL: %s:%d: "
             "Destroy sem failed"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/sem.c",
             163, errno, strerror(errno));
    fail_count++;
  }
out:
  if (fail_count == 0)
    test_msg("PASS\n");
  return fail_count;
}


x86 assembly (clang, -O0):
<test_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x54f001d,%esi
call   10b0 <ftok@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    121a <test_fn+0x7a>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x28(%rbp),%ecx
mov    %eax,%r8d
lea    0xe05(%rip),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x73,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1523 <test_fn+0x383>
mov    $0x0,%al
call   1090 <lrand48@plt>
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    0x2db0(%rip),%rax
or     (%rax),%edx
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12a1 <test_fn+0x101>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe38(%rip),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x7c,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1505 <test_fn+0x365>
mov    -0x14(%rbp),%edi
mov    0x2d0d(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%ecx
xor    %esi,%esi
mov    $0x0,%al
call   10a0 <semctl@plt>
cmp    $0xffffffff,%eax
jne    130a <test_fn+0x16a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
lea    0xdfc(%rip),%rdi
lea    0xd35(%rip),%rsi
mov    $0x81,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1498 <test_fn+0x2f8>
mov    $0x0,%al
call   1050 <test_daemon@plt>
mov    $0x0,%al
call   1070 <test_waitsig@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1080 <check_sem_by_id@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1378 <test_fn+0x1d8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    0x2c98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0xdbc(%rip),%rdi
lea    0xcc7(%rip),%rsi
mov    $0x8b,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
jmp    1498 <test_fn+0x2f8>
mov    -0x18(%rbp),%edi
call   1040 <check_sem_by_key@plt>
cmp    $0x0,%rax
jge    13d2 <test_fn+0x232>
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%r8d
lea    0xda2(%rip),%rdi
lea    0xc76(%rip),%rsi
mov    $0x90,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1498 <test_fn+0x2f8>
mov    -0x14(%rbp),%edi
mov    0x2bec(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    $0x0,%al
call   10a0 <semctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    143c <test_fn+0x29c>
mov    0x2bdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%r8d
lea    0xd70(%rip),%rdi
lea    0xc0c(%rip),%rsi
mov    $0x97,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1498 <test_fn+0x2f8>
cmpl   $0x0,-0x1c(%rbp)
je     1493 <test_fn+0x2f3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2b85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    %eax,%r9d
lea    0xd4c(%rip),%rdi
lea    0xbb0(%rip),%rsi
mov    $0x9c,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1498 <test_fn+0x2f8>
mov    -0x14(%rbp),%edi
mov    0x2b2e(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
mov    $0x0,%al
call   10a0 <semctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1500 <test_fn+0x360>
mov    0x2b14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x48(%rbp),%ecx
mov    %eax,%r8d
lea    0xd16(%rip),%rdi
lea    0xb43(%rip),%rsi
mov    $0xa3,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1505 <test_fn+0x365>
cmpl   $0x0,-0x24(%rbp)
jne    151d <test_fn+0x37d>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1060 <test_msg@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rdi
mov    $0x54f001d,%esi
call   10b0 <ftok@plt>
cmp    $0xffffffff,%eax
je     12ad <test_fn+0x10d>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <lrand48@plt>
mov    %eax,%ebp
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    0x2e18(%rip),%rax
or     (%rax),%edx
or     $0x1ff,%edx
mov    $0x1,%r15d
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
je     12e7 <test_fn+0x147>
mov    %eax,%r14d
and    $0x7,%ebp
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   10a0 <semctl@plt>
cmp    $0xffffffff,%eax
je     131b <test_fn+0x17b>
xor    %eax,%eax
call   1050 <test_daemon@plt>
xor    %eax,%eax
call   1070 <test_waitsig@plt>
mov    %r14d,%edi
mov    %ebp,%esi
call   1080 <check_sem_by_id@plt>
test   %eax,%eax
js     1340 <test_fn+0x1a0>
mov    %ebx,%edi
call   1040 <check_sem_by_key@plt>
test   %rax,%rax
js     1365 <test_fn+0x1c5>
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10a0 <semctl@plt>
test   %eax,%eax
js     138a <test_fn+0x1ea>
je     1420 <test_fn+0x280>
mov    %eax,%ebx
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xf36(%rip),%rdi
lea    0xd9a(%rip),%rsi
mov    $0x9c,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <test_msg@plt>
jmp    13b9 <test_fn+0x219>
mov    0x2d24(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xd3c(%rip),%rdi
lea    0xd63(%rip),%rsi
mov    $0x73,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <test_msg@plt>
mov    $0xffffffff,%r15d
jmp    1412 <test_fn+0x272>
mov    0x2cea(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xdc3(%rip),%rdi
lea    0xd29(%rip),%rsi
mov    $0x7c,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <test_msg@plt>
jmp    1412 <test_fn+0x272>
mov    0x2cb6(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xdbc(%rip),%rdi
lea    0xcf5(%rip),%rsi
mov    $0x81,%edx
jmp    13ad <test_fn+0x20d>
mov    0x2c91(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xdc5(%rip),%rdi
lea    0xcd0(%rip),%rsi
mov    $0x8b,%edx
jmp    13ad <test_fn+0x20d>
mov    0x2c6c(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xdd7(%rip),%rdi
lea    0xcab(%rip),%rsi
mov    $0x90,%edx
jmp    13ad <test_fn+0x20d>
mov    0x2c47(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xdea(%rip),%rdi
lea    0xc86(%rip),%rsi
mov    $0x97,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <test_msg@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%r15d
mov    %r14d,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   10a0 <semctl@plt>
test   %eax,%eax
jns    1412 <test_fn+0x272>
mov    $0x2,%ebp
mov    0x2bf1(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xe03(%rip),%rdi
lea    0xc30(%rip),%rsi
mov    $0xa3,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <test_msg@plt>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ba9(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    $0x1,%ebp
mov    %r14d,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   10a0 <semctl@plt>
test   %eax,%eax
js     13e0 <test_fn+0x240>
lea    0xde2(%rip),%rdi
xor    %eax,%eax
call   1060 <test_msg@plt>
jmp    1412 <test_fn+0x272>

LLVM IR (-O0):
@.str = [46 x i8] c"ERR: %s:%d: Can't make key (errno = %d (%s))\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/sem.c\00"
@errno = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.2 = [45 x i8] c"ERR: %s:%d: Can't get sem (errno = %d (%s))\0A\00"
@SETVAL = global i32 0
@.str.3 = [46 x i8] c"ERR: %s:%d: Can't init sem (errno = %d (%s))\0A\00"
@.str.4 = [55 x i8] c"FAIL: %s:%d: Check sem by id failed (errno = %d (%s))\0A\00"
@.str.5 = [56 x i8] c"FAIL: %s:%d: Check sem by key failed (errno = %d (%s))\0A\00"
@GETVAL = global i32 0
@.str.6 = [56 x i8] c"FAIL: %s:%d: Failed to get sem value (errno = %d (%s))\0A\00"
@.str.7 = [55 x i8] c"FAIL: %s:%d: Non-zero sem value: %d (errno = %d (%s))\0A\00"
@IPC_RMID = global i32 0
@.str.8 = [51 x i8] c"FAIL: %s:%d: Destroy sem failed (errno = %d (%s))\0A\00"
@.str.9 = [6 x i8] c"PASS\0A\00"
define i32 @test_fn(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @ftok(i8* %13, i32 89063453)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 115, i32 %18, i32 %20)
store i32 -1, i32* %3
br label %125
22: ; preds = %2
%23 = call i32 (...) @lrand48()
%24 = and i32 %23, 7
store i32 %24, i32* %8
%25 = load i32, i32* %7
%26 = load i32, i32* @IPC_CREAT
%27 = or i32 511, %26
%28 = load i32, i32* @IPC_EXCL
%29 = or i32 %27, %28
%30 = call i32 @semget(i32 %25, i32 1, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %40
33: ; preds = %22
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
%36 = load i32, i32* @errno
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 124, i32 %36, i32 %38)
br label %118
40: ; preds = %22
%41 = load i32, i32* %6
%42 = load i32, i32* @SETVAL
%43 = load i32, i32* %8
%44 = call i32 (i32, i32, i32, ...) @semctl(i32 %41, i32 0, i32 %42, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %53
46: ; preds = %40
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
%49 = load i32, i32* @errno
%50 = load i32, i32* @errno
%51 = call i32 @strerror(i32 %50)
%52 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 129, i32 %49, i32 %51)
br label %104
53: ; preds = %40
%54 = call i32 (...) @test_daemon()
%55 = call i32 (...) @test_waitsig()
%56 = load i32, i32* %6
%57 = load i32, i32* %8
%58 = call i32 @check_sem_by_id(i32 %56, i32 %57)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %53
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
%64 = load i32, i32* @errno
%65 = load i32, i32* @errno
%66 = call i32 @strerror(i32 %65)
%67 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 139, i32 %64, i32 %66)
br label %104
68: ; preds = %53
%69 = load i32, i32* %7
%70 = call i64 @check_sem_by_key(i32 %69)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = load i32, i32* @errno
%74 = load i32, i32* @errno
%75 = call i32 @strerror(i32 %74)
%76 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 144, i32 %73, i32 %75)
%77 = load i32, i32* %10
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
br label %104
79: ; preds = %68
%80 = load i32, i32* %6
%81 = load i32, i32* @GETVAL
%82 = call i32 (i32, i32, i32, ...) @semctl(i32 %80, i32 0, i32 %81)
store i32 %82, i32* %8
%83 = load i32, i32* %8
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %79
%86 = load i32, i32* @errno
%87 = load i32, i32* @errno
%88 = call i32 @strerror(i32 %87)
%89 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 151, i32 %86, i32 %88)
%90 = load i32, i32* %10
%91 = add nsw i32 %90, 1
store i32 %91, i32* %10
br label %104
92: ; preds = %79
%93 = load i32, i32* %8
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %103
95: ; preds = %92
%96 = load i32, i32* %8
%97 = load i32, i32* @errno
%98 = load i32, i32* @errno
%99 = call i32 @strerror(i32 %98)
%100 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 156, i32 %96, i32 %97, i32 %99)
%101 = load i32, i32* %10
%102 = add nsw i32 %101, 1
store i32 %102, i32* %10
br label %103
103: ; preds = %95, %92
br label %104
104: ; preds = %103, %85, %72, %61, %46
%105 = load i32, i32* %6
%106 = load i32, i32* @IPC_RMID
%107 = call i32 (i32, i32, i32, ...) @semctl(i32 %105, i32 1, i32 %106)
store i32 %107, i32* %9
%108 = load i32, i32* %9
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %117
110: ; preds = %104
%111 = load i32, i32* @errno
%112 = load i32, i32* @errno
%113 = call i32 @strerror(i32 %112)
%114 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 163, i32 %111, i32 %113)
%115 = load i32, i32* %10
%116 = add nsw i32 %115, 1
store i32 %116, i32* %10
br label %117
117: ; preds = %110, %104
br label %118
118: ; preds = %117, %33
%119 = load i32, i32* %10
%120 = icmp eq i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %118
%122 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %123
123: ; preds = %121, %118
%124 = load i32, i32* %10
store i32 %124, i32* %3
br label %125
125: ; preds = %123, %17
%126 = load i32, i32* %3
ret i32 %126
}

LLVM IR (-O2):
@.str = [46 x i8] c"ERR: %s:%d: Can't make key (errno = %d (%s))\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/sem.c\00"
@errno = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str.2 = [45 x i8] c"ERR: %s:%d: Can't get sem (errno = %d (%s))\0A\00"
@SETVAL = global i32 0
@.str.3 = [46 x i8] c"ERR: %s:%d: Can't init sem (errno = %d (%s))\0A\00"
@.str.4 = [55 x i8] c"FAIL: %s:%d: Check sem by id failed (errno = %d (%s))\0A\00"
@.str.5 = [56 x i8] c"FAIL: %s:%d: Check sem by key failed (errno = %d (%s))\0A\00"
@GETVAL = global i32 0
@.str.6 = [56 x i8] c"FAIL: %s:%d: Failed to get sem value (errno = %d (%s))\0A\00"
@.str.7 = [55 x i8] c"FAIL: %s:%d: Non-zero sem value: %d (errno = %d (%s))\0A\00"
@IPC_RMID = global i32 0
@.str.8 = [51 x i8] c"FAIL: %s:%d: Destroy sem failed (errno = %d (%s))\0A\00"
@.str.9 = [6 x i8] c"PASS\0A\00"
define i32 @test_fn(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @ftok(i8* %3, i32 89063453)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 115, i32 %7, i32 %8)
br label %76
10: ; preds = %2
%11 = tail call i32 (...) @lrand48()
%12 = and i32 %11, 7
%13 = load i32, i32* @IPC_CREAT
%14 = load i32, i32* @IPC_EXCL
%15 = or i32 %13, %14
%16 = or i32 %15, 511
%17 = tail call i32 @semget(i32 %4, i32 1, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* @errno
%21 = tail call i32 @strerror(i32 %20)
%22 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 124, i32 %20, i32 %21)
br label %76
23: ; preds = %10
%24 = load i32, i32* @SETVAL
%25 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %17, i32 0, i32 %24, i32 %12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @errno
%29 = tail call i32 @strerror(i32 %28)
%30 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 129, i32 %28, i32 %29)
br label %61
31: ; preds = %23
%32 = tail call i32 (...) @test_daemon()
%33 = tail call i32 (...) @test_waitsig()
%34 = tail call i32 @check_sem_by_id(i32 %17, i32 %12)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* @errno
%38 = tail call i32 @strerror(i32 %37)
%39 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 139, i32 %37, i32 %38)
br label %61
40: ; preds = %31
%41 = tail call i64 @check_sem_by_key(i32 %4)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* @errno
%45 = tail call i32 @strerror(i32 %44)
%46 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 144, i32 %44, i32 %45)
br label %61
47: ; preds = %40
%48 = load i32, i32* @GETVAL
%49 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %17, i32 0, i32 %48)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* @errno
%53 = tail call i32 @strerror(i32 %52)
%54 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 151, i32 %52, i32 %53)
br label %61
55: ; preds = %47
%56 = icmp eq i32 %49, 0
br i1 %56, label %65, label %57
57: ; preds = %55
%58 = load i32, i32* @errno
%59 = tail call i32 @strerror(i32 %58)
%60 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 156, i32 %49, i32 %58, i32 %59)
br label %61
61: ; preds = %57, %51, %43, %36, %27
%62 = load i32, i32* @IPC_RMID
%63 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %17, i32 1, i32 %62)
%64 = icmp slt i32 %63, 0
br i1 %64, label %69, label %76
65: ; preds = %55
%66 = load i32, i32* @IPC_RMID
%67 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %17, i32 1, i32 %66)
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %65, %61
%70 = phi i32 [ 1, %65 ], [ 2, %61 ]
%71 = load i32, i32* @errno
%72 = tail call i32 @strerror(i32 %71)
%73 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 163, i32 %71, i32 %72)
br label %76
74: ; preds = %65
%75 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %76
76: ; preds = %61, %69, %19, %74, %6
%77 = phi i32 [ -1, %6 ], [ 0, %74 ], [ %70, %69 ], [ 1, %19 ], [ 1, %61 ]
ret i32 %77
}