#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*/ _IO(int, int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int flush(void) {
  int fd_logger;
  int ret;
  fd_logger = open("/dev/logger", 0);
  if (fd_logger < 0) {
    printf("Open /dev/logger failed\n");
    return -1;
  }
  ret = ioctl(fd_logger, _IO(0XAF, 0));
  if (ret < 0) {
    printf("Flush failed\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<flush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117b <flush+0x3b>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <flush+0x83>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0xaf,%edi
xor    %esi,%esi
call   1040 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11bc <flush+0x7c>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <flush+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
js     117b <flush+0x3b>
mov    %eax,%ebp
mov    $0xaf,%edi
xor    %esi,%esi
call   1040 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %eax,%eax
jns    118c <flush+0x4c>
lea    0xe93(%rip),%rdi
jmp    1182 <flush+0x42>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/logger\00"
@.str.1 = [25 x i8] c"Open /dev/logger failed\0A\00"
@.str.2 = [14 x i8] c"Flush failed\0A\00"
define i32 @flush() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @_IO(i32 175, i32 0)
%12 = call i32 @ioctl(i32 %10, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
17: ; preds = %9
store i32 0, i32* %1
br label %18
18: ; preds = %17, %15, %7
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/logger\00"
@str = [13 x i8] c"Flush failed\00"
@str.3 = [24 x i8] c"Open /dev/logger failed\00"
define i32 @flush() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = icmp slt i32 %1, 0
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i32 @_IO(i32 175, i32 0)
%5 = tail call i32 @ioctl(i32 %1, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3, %0
%8 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0), %0 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %3 ]
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
br label %10
10: ; preds = %7, %3
%11 = phi i32 [ 0, %3 ], [ -1, %7 ]
ret i32 %11
}