#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 */
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
int TEMP_FAILURE_RETRY(int /*<<< orphan*/);
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ puts(char *);
int sem_init(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
int do_test(void) {
  sem_t s;
  if (sem_init(&s, 0, 0) == -1) {
    puts("init failed");
    return 1;
  }
  alarm(1);
  if (TEMP_FAILURE_RETRY(sem_wait(&s)) == -1) {
    puts("wait failed");
    return 1;
  }
  puts("wait succeeded");
  return 1;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <sem_init@plt>
cmp    $0xffffffff,%eax
jne    1186 <do_test+0x36>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <do_test+0x84>
mov    $0x1,%edi
call   1050 <alarm@plt>
lea    -0x8(%rbp),%rdi
call   1030 <sem_wait@plt>
mov    %eax,%edi
call   1070 <TEMP_FAILURE_RETRY@plt>
cmp    $0xffffffff,%eax
jne    11c1 <do_test+0x71>
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <do_test+0x84>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rax
lea    0x4(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <sem_init@plt>
cmp    $0xffffffff,%eax
je     1196 <do_test+0x46>
mov    $0x1,%edi
call   1050 <alarm@plt>
lea    0x4(%rsp),%rdi
call   1030 <sem_wait@plt>
mov    %eax,%edi
call   1070 <TEMP_FAILURE_RETRY@plt>
cmp    $0xffffffff,%eax
lea    0xe83(%rip),%rax
lea    0xe88(%rip),%rdi
cmove  %rax,%rdi
jmp    119d <do_test+0x4d>
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"init failed\00"
@.str.1 = [12 x i8] c"wait failed\00"
@.str.2 = [15 x i8] c"wait succeeded\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @sem_init(i32* %2, i32 0, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %16
7: ; preds = %0
%8 = call i32 @alarm(i32 1)
%9 = call i32 @sem_wait(i32* %2)
%10 = call i32 @TEMP_FAILURE_RETRY(i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %16
14: ; preds = %7
%15 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %16
16: ; preds = %14, %12, %5
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [12 x i8] c"init failed\00"
@.str.1 = [12 x i8] c"wait failed\00"
@.str.2 = [15 x i8] c"wait succeeded\00"
define i32 @do_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sem_init(i32* %1, i32 0, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = call i32 @alarm(i32 1)
%7 = call i32 @sem_wait(i32* %1)
%8 = call i32 @TEMP_FAILURE_RETRY(i32 %7)
%9 = icmp eq i32 %8, -1
%10 = select i1 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0)
br label %11
11: ; preds = %5, %0
%12 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %0 ], [ %10, %5 ]
%13 = call i32 @puts(i8* dereferenceable(1) %12)
ret i32 1
}