#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 otrap {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ otrap_deinit(struct otrap *);
int /*<<< orphan*/ *otrap_file(struct otrap *);
size_t otrap_skip(struct otrap *, size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
void skip(struct otrap *trap, const char *output) {
  static int call = 0;
  ++call;
  FILE *f = otrap_file(trap);
  size_t output_size = strlen(output);
  fputs(output, f);
  size_t skipped = otrap_skip(trap, output_size);
  if (skipped != output_size) {
    fprintf(stderr,
            "Did not skip the right number of characters on the #%d call.\n",
            call);
    otrap_deinit(trap);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<skip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ed6(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ecd(%rip)
mov    -0x8(%rbp),%rdi
call   1040 <otrap_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <otrap_skip@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1203 <skip+0x93>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%edx
lea    0xe15(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <otrap_deinit@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
addl   $0x1,0x2ed7(%rip)
call   1040 <otrap_file@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <fputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <otrap_skip@plt>
cmp    %rbx,%rax
jne    11bf <skip+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    0x2e8e(%rip),%edx
lea    0xe2b(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <otrap_deinit@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.otrap = type { i32 }
@skip.call = internal global i32 0
@stderr = global i32 0
@.str = [62 x i8] c"Did not skip the right number of characters on the #%d call.\0A\00"
define void @skip(%struct.otrap* %0, i8* %1) {
%3 = alloca %struct.otrap*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store %struct.otrap* %0, %struct.otrap** %3
store i8* %1, i8** %4
%8 = load i32, i32* @skip.call
%9 = add nsw i32 %8, 1
store i32 %9, i32* @skip.call
%10 = load %struct.otrap*, %struct.otrap** %3
%11 = call i32* @otrap_file(%struct.otrap* %10)
store i32* %11, i32** %5
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %6
%14 = load i8*, i8** %4
%15 = load i32*, i32** %5
%16 = call i32 @fputs(i8* %14, i32* %15)
%17 = load %struct.otrap*, %struct.otrap** %3
%18 = load i64, i64* %6
%19 = call i64 @otrap_skip(%struct.otrap* %17, i64 %18)
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = load i64, i64* %6
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i32, i32* @skip.call
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load %struct.otrap*, %struct.otrap** %3
%28 = call i32 @otrap_deinit(%struct.otrap* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.otrap = type { i32 }
@skip.call = internal unnamed_addr global i32 0
@stderr = global i32 0
@.str = [62 x i8] c"Did not skip the right number of characters on the #%d call.\0A\00"
define void @skip(%struct.otrap* %0, i8* nocapture %1) {
%3 = load i32, i32* @skip.call
%4 = add nsw i32 %3, 1
store i32 %4, i32* @skip.call
%5 = tail call i32* @otrap_file(%struct.otrap* %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i32 @fputs(i8* %1, i32* %5)
%8 = tail call i64 @otrap_skip(%struct.otrap* %0, i64 %6)
%9 = icmp eq i64 %8, %6
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @skip.call
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call i32 @otrap_deinit(%struct.otrap* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
ret void
}