#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ ioctl(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void trigger_reipl(void) {
  int fh;
  fh = open("/dev/zcore", O_RDWR);
  if (fh == -1) {
    {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "open %s failed", "/dev/zcore");
      perror("");
    };
    return;
  }
  ioctl(fh, 0x5, 0);
  close(fh);
}


x86 assembly (clang, -O0):
<trigger_reipl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11c0 <trigger_reipl+0x70>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
lea    0xe58(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
jmp    11d7 <trigger_reipl+0x87>
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trigger_reipl>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1183 <trigger_reipl+0x33>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1040 <close@plt>
mov    0x2e4e(%rip),%rbx
mov    (%rbx),%edi
lea    0xe78(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe70(%rip),%rsi
lea    0xe56(%rip),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe5a(%rip),%rdi
pop    %rbx
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/zcore\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"ERROR: \00"
@.str.2 = [15 x i8] c"open %s failed\00"
@.str.3 = [1 x i8] zeroinitializer
define void @trigger_reipl() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %17
12: ; preds = %0
%13 = load i32, i32* %1
%14 = call i32 @ioctl(i32 %13, i32 5, i32 0)
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
br label %17
17: ; preds = %12, %6
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/zcore\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"ERROR: \00"
@.str.2 = [15 x i8] c"open %s failed\00"
@.str.3 = [1 x i8] zeroinitializer
define void @trigger_reipl() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %13
10: ; preds = %0
%11 = tail call i32 @ioctl(i32 %2, i32 5, i32 0)
%12 = tail call i32 @close(i32 %2)
br label %13
13: ; preds = %10, %4
ret void
}