#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int iretdTest();
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int result;
  int ok = 0;
  int tests = 0;
  ((void)0);
  tests++;
  fprintf(stderr, "Calling iret\n");
  result = iretdTest();
  fprintf(stderr, "iretd result = %d %s\n", result,
          result == -1 ? "OK" : "***ERROR***");
  ok += (result == -1);
  return (ok == tests) ? 0 : -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)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1040 <iretdTest@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%esi
lea    0xea3(%rip),%rcx
lea    0xe99(%rip),%rax
cmp    $0xffffffff,%esi
cmove  %rax,%rcx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0xffffffff,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%esi
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb8(%rip),%rbx
mov    (%rbx),%edi
lea    0xecf(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1040 <iretdTest@plt>
mov    (%rbx),%edi
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
setne  %bl
lea    0xed4(%rip),%rdx
lea    0xed0(%rip),%rcx
cmove  %rdx,%rcx
lea    0xeac(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
neg    %ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Calling iret\0A\00"
@.str.1 = [22 x i8] c"iretd result = %d %s\0A\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [12 x i8] c"***ERROR***\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
store i32 %10, i32* %8
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (...) @iretdTest()
store i32 %13, i32* %6
%14 = load i32, i32* @stderr
%15 = load i32, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %19)
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
%23 = zext i1 %22 to i32
%24 = load i32, i32* %7
%25 = add nsw i32 %24, %23
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = icmp eq i32 %26, %27
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 0, i32 -1
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Calling iret\0A\00"
@.str.1 = [22 x i8] c"iretd result = %d %s\0A\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [12 x i8] c"***ERROR***\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (...) @iretdTest()
%6 = load i32, i32* @stderr
%7 = icmp eq i32 %5, -1
%8 = select i1 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0)
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %5, i8* %8)
%10 = xor i1 %7, true
%11 = sext i1 %10 to i32
ret i32 %11
}