#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int read(int, char *, int);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
int easypen_init(int fd, unsigned long *id, unsigned long *extra) {
  char buf[256];
  write(fd, 0, 1);
  usleep(400000);
  if (write(fd, "B", 1) == -1)
    return -1;
  while (read(fd, buf, sizeof(buf)) == sizeof(buf))
    ;
  if (write(fd,
            "F"
            "@"
            "b",
            3) == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<easypen_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x61a80,%edi
call   1050 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    0xe95(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    118a <easypen_init+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <easypen_init+0xb6>
jmp    118f <easypen_init+0x5f>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
cltq
cmp    $0x100,%rax
jne    11b6 <easypen_init+0x86>
jmp    118f <easypen_init+0x5f>
mov    -0x8(%rbp),%edi
lea    0xe42(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11df <easypen_init+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <easypen_init+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<easypen_init>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x61a80,%edi
call   1050 <usleep@plt>
lea    0xea7(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11a7 <easypen_init+0x77>
mov    %rsp,%r14
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
cmp    $0x100,%eax
je     1170 <easypen_init+0x40>
lea    0xe75(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    11ac <easypen_init+0x7c>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"B\00"
@.str.1 = [4 x i8] c"F@b\00"
define i32 @easypen_init(i32 %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca [256 x i8]
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%9 = load i32, i32* %5
%10 = call i32 @write(i32 %9, i8* null, i32 1)
%11 = call i32 @usleep(i32 400000)
%12 = load i32, i32* %5
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %30
16: ; preds = %3
br label %17
17: ; preds = %23, %16
%18 = load i32, i32* %5
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 256)
%21 = sext i32 %20 to i64
%22 = icmp eq i64 %21, 256
br i1 %22, label %23, label %24
23: ; preds = %17
br label %17
24: ; preds = %17
%25 = load i32, i32* %5
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %4
br label %30
29: ; preds = %24
store i32 0, i32* %4
br label %30
30: ; preds = %29, %28, %15
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"B\00"
@.str.1 = [4 x i8] c"F@b\00"
define i32 @easypen_init(i32 %0, i64* nocapture readnone %1, i64* nocapture readnone %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @write(i32 %0, i8* null, i32 1)
%7 = tail call i32 @usleep(i32 400000)
%8 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %17, label %10
10: ; preds = %3, %10
%11 = call i32 @read(i32 %0, i8* %5, i32 256)
%12 = icmp eq i32 %11, 256
br i1 %12, label %10, label %13
13: ; preds = %10
%14 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%15 = icmp eq i32 %14, -1
%16 = sext i1 %15 to i32
br label %17
17: ; preds = %13, %3
%18 = phi i32 [ -1, %3 ], [ %16, %13 ]
ret i32 %18
}