#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*/ MTBSR;
int /*<<< orphan*/ MTFSFM;
int /*<<< orphan*/ MTIOCTOP;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, struct mtop *);
int /*<<< orphan*/ stderr;
void tape_forwards(int fd) {
  int ret;
  struct mtop mymtop;
  mymtop.mt_count = 1;
  mymtop.mt_op = MTFSFM;
  ret = ioctl(fd, MTIOCTOP, &mymtop);
  if (ret != 0) {
    fprintf(stderr, "Tape operation FSFM failed.\n");
    exit(1);
  }
  mymtop.mt_count = 1;
  mymtop.mt_op = MTBSR;
  ret = ioctl(fd, MTIOCTOP, &mymtop);
  if (ret != 0) {
    fprintf(stderr, "Tape operation BSR failed.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<tape_forwards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118f <tape_forwards+0x5f>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x1,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e3 <tape_forwards+0xb3>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tape_forwards>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x1,(%rsp)
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e8f(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
jne    118d <tape_forwards+0x5d>
movl   $0x1,(%rsp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    (%r14),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    119f <tape_forwards+0x6f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
jmp    11af <tape_forwards+0x7f>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.mtop = type { i32, i32 }
@MTFSFM = global i32 0
@MTIOCTOP = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Tape operation FSFM failed.\0A\00"
@MTBSR = global i32 0
@.str.1 = [28 x i8] c"Tape operation BSR failed.\0A\00"
define void @tape_forwards(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.mtop
store i32 %0, i32* %2
%5 = getelementptr inbounds %struct.mtop, %struct.mtop* %4, i32 0, i32 0
store i32 1, i32* %5
%6 = load i32, i32* @MTFSFM
%7 = getelementptr inbounds %struct.mtop, %struct.mtop* %4, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* %2
%9 = load i32, i32* @MTIOCTOP
%10 = call i32 @ioctl(i32 %8, i32 %9, %struct.mtop* %4)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = getelementptr inbounds %struct.mtop, %struct.mtop* %4, i32 0, i32 0
store i32 1, i32* %18
%19 = load i32, i32* @MTBSR
%20 = getelementptr inbounds %struct.mtop, %struct.mtop* %4, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = load i32, i32* @MTIOCTOP
%23 = call i32 @ioctl(i32 %21, i32 %22, %struct.mtop* %4)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.mtop = type { i32, i32 }
@MTFSFM = global i32 0
@MTIOCTOP = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Tape operation FSFM failed.\0A\00"
@MTBSR = global i32 0
@.str.1 = [28 x i8] c"Tape operation BSR failed.\0A\00"
define void @tape_forwards(i32 %0) {
%2 = alloca %struct.mtop
%3 = bitcast %struct.mtop* %2 to i8*
%4 = getelementptr inbounds %struct.mtop, %struct.mtop* %2, i64 0, i32 0
store i32 1, i32* %4
%5 = load i32, i32* @MTFSFM
%6 = getelementptr inbounds %struct.mtop, %struct.mtop* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = load i32, i32* @MTIOCTOP
%8 = call i32 @ioctl(i32 %0, i32 %7, %struct.mtop* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
store i32 1, i32* %4
%15 = load i32, i32* @MTBSR
store i32 %15, i32* %6
%16 = load i32, i32* @MTIOCTOP
%17 = call i32 @ioctl(i32 %0, i32 %16, %struct.mtop* %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
ret void
}