#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*/ MTLOAD;
int /*<<< orphan*/ MTOFFL;
int /*<<< orphan*/ MTREW;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, struct mtop *);
int /*<<< orphan*/ stderr;
void load_next(int fd) {
  int ret;
  struct mtop mymtop;
  mymtop.mt_count = 1;
  mymtop.mt_op = MTOFFL;
  ret = ioctl(fd, MTIOCTOP, &mymtop);
  if (ret != 0) {
    fprintf(stderr, "Tape operation OFFL failed.\n");
    exit(1);
  }
  mymtop.mt_count = 1;
  mymtop.mt_op = MTLOAD;
  ret = ioctl(fd, MTIOCTOP, &mymtop);
  if (ret != 0) {
    fprintf(stderr, "Tape operation LOAD failed.\n");
    exit(1);
  } else
    fprintf(stderr, "done\n");
  mymtop.mt_count = 1;
  mymtop.mt_op = MTREW;
  ret = ioctl(fd, MTIOCTOP, &mymtop);
  if (ret != 0) {
    fprintf(stderr, "Tape operation REW failed.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<load_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118f <load_next+0x5f>
mov    0x2e59(%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    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e3 <load_next+0xb3>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x10(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     124c <load_next+0x11c>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_next>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0x8(%rsp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e91(%rip),%r14
mov    (%r14),%esi
lea    0x8(%rsp),%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
jne    11d8 <load_next+0xa8>
movl   $0x1,0x8(%rsp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    (%r14),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    0x2e3d(%rip),%r15
mov    (%r15),%edi
test   %eax,%eax
jne    11ea <load_next+0xba>
lea    0xe99(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,0x8(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    (%r14),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    11f3 <load_next+0xc3>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
jmp    11fd <load_next+0xcd>
lea    0xe2c(%rip),%rsi
jmp    11fd <load_next+0xcd>
mov    (%r15),%edi
lea    0xe43(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.mtop = type { i32, i32 }
@MTOFFL = global i32 0
@MTIOCTOP = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Tape operation OFFL failed.\0A\00"
@MTLOAD = global i32 0
@.str.1 = [29 x i8] c"Tape operation LOAD failed.\0A\00"
@.str.2 = [6 x i8] c"done\0A\00"
@MTREW = global i32 0
@.str.3 = [28 x i8] c"Tape operation REW failed.\0A\00"
define void @load_next(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* @MTOFFL
%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* @MTLOAD
%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 ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %30
%34 = getelementptr inbounds %struct.mtop, %struct.mtop* %4, i32 0, i32 0
store i32 1, i32* %34
%35 = load i32, i32* @MTREW
%36 = getelementptr inbounds %struct.mtop, %struct.mtop* %4, i32 0, i32 1
store i32 %35, i32* %36
%37 = load i32, i32* %2
%38 = load i32, i32* @MTIOCTOP
%39 = call i32 @ioctl(i32 %37, i32 %38, %struct.mtop* %4)
store i32 %39, i32* %3
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %33
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %33
ret void
}

LLVM IR (-O2):
%struct.mtop = type { i32, i32 }
@MTOFFL = global i32 0
@MTIOCTOP = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Tape operation OFFL failed.\0A\00"
@MTLOAD = global i32 0
@.str.1 = [29 x i8] c"Tape operation LOAD failed.\0A\00"
@.str.2 = [6 x i8] c"done\0A\00"
@MTREW = global i32 0
@.str.3 = [28 x i8] c"Tape operation REW failed.\0A\00"
define void @load_next(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* @MTOFFL
%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* @MTLOAD
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
%19 = load i32, i32* @stderr
br i1 %18, label %23, label %20
20: ; preds = %14
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
%25 = load i32, i32* @MTREW
store i32 %25, i32* %6
%26 = load i32, i32* @MTIOCTOP
%27 = call i32 @ioctl(i32 %0, i32 %26, %struct.mtop* %2)
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
ret void
}