#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 */
struct mtop {
  int mt_count;
  int /*<<< orphan*/ mt_op;
};

/* Variables and functions */
int /*<<< orphan*/ MTIOCTOP;
int /*<<< orphan*/ MTWEOF;
int /*<<< orphan*/ error_reason(char *);
int ioctl(int, int /*<<< orphan*/, struct mtop *);
int write_tapemark(int fd, int count) {
  struct mtop op;
  op.mt_count = count;
  op.mt_op = MTWEOF;
  if (ioctl(fd, MTIOCTOP, &op) == -1) {
    error_reason("Could not write tapemark");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_tapemark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1176 <write_tapemark+0x56>
lea    0xe9b(%rip),%rdi
call   1030 <error_reason@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <write_tapemark+0x5d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_tapemark>:
push   %rax
mov    %esi,(%rsp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1040 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     114d <write_tapemark+0x2d>
pop    %rcx
ret
lea    0xeac(%rip),%rdi
call   1030 <error_reason@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.mtop = type { i32, i32 }
@MTWEOF = global i32 0
@MTIOCTOP = global i32 0
@.str = [25 x i8] c"Could not write tapemark\00"
define i32 @write_tapemark(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.mtop
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = getelementptr inbounds %struct.mtop, %struct.mtop* %6, i32 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @MTWEOF
%10 = getelementptr inbounds %struct.mtop, %struct.mtop* %6, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* %4
%12 = load i32, i32* @MTIOCTOP
%13 = call i32 @ioctl(i32 %11, i32 %12, %struct.mtop* %6)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @error_reason(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %18
17: ; preds = %2
store i32 0, i32* %3
br label %18
18: ; preds = %17, %15
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.mtop = type { i32, i32 }
@MTWEOF = global i32 0
@MTIOCTOP = global i32 0
@.str = [25 x i8] c"Could not write tapemark\00"
define i32 @write_tapemark(i32 %0, i32 %1) {
%3 = alloca %struct.mtop
%4 = bitcast %struct.mtop* %3 to i8*
%5 = getelementptr inbounds %struct.mtop, %struct.mtop* %3, i64 0, i32 0
store i32 %1, i32* %5
%6 = load i32, i32* @MTWEOF
%7 = getelementptr inbounds %struct.mtop, %struct.mtop* %3, i64 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @MTIOCTOP
%9 = call i32 @ioctl(i32 %0, i32 %8, %struct.mtop* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @error_reason(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %2, %11
%14 = phi i32 [ -1, %11 ], [ 0, %2 ]
ret i32 %14
}