#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_init(int, char **);
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
int main(int argc, char **argv) {
  int id, key, val;
  int ret, fail_count = 0;
  test_init(argc, argv);
  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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             117, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             126, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             131, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             141, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             146, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             153, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             158, 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/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/sem.c",
             165, errno, strerror(errno));
    fail_count++;
  }
out:
  if (fail_count == 0)
    test_msg("PASS\n");
  return fail_count;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <test_init@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x54f001d,%esi
call   10c0 <ftok@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    123d <main+0x8d>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x28(%rbp),%ecx
mov    %eax,%r8d
lea    0xde2(%rip),%rdi
lea    0xe09(%rip),%rsi
mov    $0x75,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1546 <main+0x396>
mov    $0x0,%al
call   10a0 <lrand48@plt>
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    0x2d8d(%rip),%rax
or     (%rax),%edx
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12c4 <main+0x114>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe19(%rip),%rdi
lea    0xd7b(%rip),%rsi
mov    $0x7e,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
jmp    1528 <main+0x378>
mov    -0x14(%rbp),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%ecx
xor    %esi,%esi
mov    $0x0,%al
call   10b0 <semctl@plt>
cmp    $0xffffffff,%eax
jne    132d <main+0x17d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
lea    0xddd(%rip),%rdi
lea    0xd12(%rip),%rsi
mov    $0x83,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
jmp    14bb <main+0x30b>
mov    $0x0,%al
call   1060 <test_daemon@plt>
mov    $0x0,%al
call   1080 <test_waitsig@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1090 <check_sem_by_id@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    139b <main+0x1eb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0xd9d(%rip),%rdi
lea    0xca4(%rip),%rsi
mov    $0x8d,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
jmp    14bb <main+0x30b>
mov    -0x18(%rbp),%edi
call   1050 <check_sem_by_key@plt>
cmp    $0x0,%rax
jge    13f5 <main+0x245>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%r8d
lea    0xd83(%rip),%rdi
lea    0xc53(%rip),%rsi
mov    $0x92,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    14bb <main+0x30b>
mov    -0x14(%rbp),%edi
mov    0x2bc9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    $0x0,%al
call   10b0 <semctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    145f <main+0x2af>
mov    0x2bba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%r8d
lea    0xd51(%rip),%rdi
lea    0xbe9(%rip),%rsi
mov    $0x99,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    14bb <main+0x30b>
cmpl   $0x0,-0x1c(%rbp)
je     14b6 <main+0x306>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2b62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    %eax,%r9d
lea    0xd2d(%rip),%rdi
lea    0xb8d(%rip),%rsi
mov    $0x9e,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    14bb <main+0x30b>
mov    -0x14(%rbp),%edi
mov    0x2b0b(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
mov    $0x0,%al
call   10b0 <semctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1523 <main+0x373>
mov    0x2af1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2ae5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x48(%rbp),%ecx
mov    %eax,%r8d
lea    0xcf7(%rip),%rdi
lea    0xb20(%rip),%rsi
mov    $0xa5,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1528 <main+0x378>
cmpl   $0x0,-0x24(%rbp)
jne    1540 <main+0x390>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1070 <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):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1040 <test_init@plt>
mov    (%rbx),%rdi
mov    $0x54f001d,%esi
call   10c0 <ftok@plt>
cmp    $0xffffffff,%eax
je     12c5 <main+0x115>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <lrand48@plt>
mov    %eax,%ebp
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
mov    0x2e00(%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     12ff <main+0x14f>
mov    %eax,%r14d
and    $0x7,%ebp
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   10b0 <semctl@plt>
cmp    $0xffffffff,%eax
je     1333 <main+0x183>
xor    %eax,%eax
call   1060 <test_daemon@plt>
xor    %eax,%eax
call   1080 <test_waitsig@plt>
mov    %r14d,%edi
mov    %ebp,%esi
call   1090 <check_sem_by_id@plt>
test   %eax,%eax
js     1358 <main+0x1a8>
mov    %ebx,%edi
call   1050 <check_sem_by_key@plt>
test   %rax,%rax
js     137d <main+0x1cd>
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
xor    %eax,%eax
call   10b0 <semctl@plt>
test   %eax,%eax
js     13a2 <main+0x1f2>
je     1438 <main+0x288>
mov    %eax,%ebx
mov    0x2d43(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10d0 <strerror@plt>
lea    0xf22(%rip),%rdi
lea    0xd82(%rip),%rsi
mov    $0x9e,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <test_msg@plt>
jmp    13d1 <main+0x221>
mov    0x2d0c(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xd24(%rip),%rdi
lea    0xd4b(%rip),%rsi
mov    $0x75,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <test_msg@plt>
mov    $0xffffffff,%r15d
jmp    142a <main+0x27a>
mov    0x2cd2(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xdaf(%rip),%rdi
lea    0xd11(%rip),%rsi
mov    $0x7e,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <test_msg@plt>
jmp    142a <main+0x27a>
mov    0x2c9e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xda8(%rip),%rdi
lea    0xcdd(%rip),%rsi
mov    $0x83,%edx
jmp    13c5 <main+0x215>
mov    0x2c79(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xdb1(%rip),%rdi
lea    0xcb8(%rip),%rsi
mov    $0x8d,%edx
jmp    13c5 <main+0x215>
mov    0x2c54(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xdc3(%rip),%rdi
lea    0xc93(%rip),%rsi
mov    $0x92,%edx
jmp    13c5 <main+0x215>
mov    0x2c2f(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xdd6(%rip),%rdi
lea    0xc6e(%rip),%rsi
mov    $0x99,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <test_msg@plt>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%r15d
mov    %r14d,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   10b0 <semctl@plt>
test   %eax,%eax
jns    142a <main+0x27a>
mov    $0x2,%ebp
mov    0x2bd9(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xdef(%rip),%rdi
lea    0xc18(%rip),%rsi
mov    $0xa5,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <test_msg@plt>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b91(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    $0x1,%ebp
mov    %r14d,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   10b0 <semctl@plt>
test   %eax,%eax
js     13f8 <main+0x248>
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1070 <test_msg@plt>
jmp    142a <main+0x27a>

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

LLVM IR (-O2):
@.str = [46 x i8] c"ERR: %s:%d: Can't make key (errno = %d (%s))\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fbocharov/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 @main(i32 %0, i8** %1) {
%3 = tail call i32 @test_init(i32 %0, i8** %1)
%4 = load i8*, i8** %1
%5 = tail call i32 @ftok(i8* %4, i32 89063453)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 117, i32 %8, i32 %9)
br label %77
11: ; preds = %2
%12 = tail call i32 (...) @lrand48()
%13 = and i32 %12, 7
%14 = load i32, i32* @IPC_CREAT
%15 = load i32, i32* @IPC_EXCL
%16 = or i32 %14, %15
%17 = or i32 %16, 511
%18 = tail call i32 @semget(i32 %5, i32 1, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = load i32, i32* @errno
%22 = tail call i32 @strerror(i32 %21)
%23 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 126, i32 %21, i32 %22)
br label %77
24: ; preds = %11
%25 = load i32, i32* @SETVAL
%26 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %18, i32 0, i32 %25, i32 %13)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* @errno
%30 = tail call i32 @strerror(i32 %29)
%31 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 131, i32 %29, i32 %30)
br label %62
32: ; preds = %24
%33 = tail call i32 (...) @test_daemon()
%34 = tail call i32 (...) @test_waitsig()
%35 = tail call i32 @check_sem_by_id(i32 %18, i32 %13)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @errno
%39 = tail call i32 @strerror(i32 %38)
%40 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 141, i32 %38, i32 %39)
br label %62
41: ; preds = %32
%42 = tail call i64 @check_sem_by_key(i32 %5)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* @errno
%46 = tail call i32 @strerror(i32 %45)
%47 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 146, i32 %45, i32 %46)
br label %62
48: ; preds = %41
%49 = load i32, i32* @GETVAL
%50 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %18, i32 0, i32 %49)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i32, i32* @errno
%54 = tail call i32 @strerror(i32 %53)
%55 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 153, i32 %53, i32 %54)
br label %62
56: ; preds = %48
%57 = icmp eq i32 %50, 0
br i1 %57, label %66, label %58
58: ; preds = %56
%59 = load i32, i32* @errno
%60 = tail call i32 @strerror(i32 %59)
%61 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 158, i32 %50, i32 %59, i32 %60)
br label %62
62: ; preds = %58, %52, %44, %37, %28
%63 = load i32, i32* @IPC_RMID
%64 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %18, i32 1, i32 %63)
%65 = icmp slt i32 %64, 0
br i1 %65, label %70, label %77
66: ; preds = %56
%67 = load i32, i32* @IPC_RMID
%68 = tail call i32 (i32, i32, i32, ...) @semctl(i32 %18, i32 1, i32 %67)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66, %62
%71 = phi i32 [ 1, %66 ], [ 2, %62 ]
%72 = load i32, i32* @errno
%73 = tail call i32 @strerror(i32 %72)
%74 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 165, i32 %72, i32 %73)
br label %77
75: ; preds = %66
%76 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %77
77: ; preds = %62, %70, %20, %75, %7
%78 = phi i32 [ -1, %7 ], [ 0, %75 ], [ %71, %70 ], [ 1, %20 ], [ 1, %62 ]
ret i32 %78
}