#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 */

/* Variables and functions */
int envia(int, char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int pollIn(int, int);
int recibe(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, long, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, long *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
long r_seek(int fd, long offset, int pos_origen) {
  int rc, r_errno;
  long pos_actual;
  char cadena[300] = "";
  sprintf(cadena, "r_seek %ld %d\n", offset, pos_origen);
  if (envia(fd, cadena, strlen(cadena)) == -1) {
    perror("r_seek(): envia()");
    return -1;
  }
  rc = pollIn(fd, 3000);
  if (rc == 1) {
    fprintf(stderr, "r_seek(): pollIn(): timeout\n");
    return -1;
  }
  rc = 0;
  while (rc == 0) {
    rc = recibe(fd, cadena, 300);
    if (rc == -1) {
      perror("r_seek(): recibe()");
      return -1;
    }
  }
  sscanf(cadena, "%d %ld", &r_errno, &pos_actual);
  if (r_errno != 0) {
    errno = r_errno;
    return -1;
  }
  return pos_actual;
}


x86 assembly (clang, -O0):
<r_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1060 <memset@plt>
lea    -0x160(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe33(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x16c(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x160(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x16c(%rbp),%edi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
cmp    $0xffffffff,%eax
jne    122b <r_seek+0x9b>
lea    0xdf6(%rip),%rdi
call   10a0 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12fd <r_seek+0x16d>
mov    -0xc(%rbp),%edi
mov    $0xbb8,%esi
call   1070 <pollIn@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1267 <r_seek+0xd7>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1080 <fprintf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12fd <r_seek+0x16d>
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    12b7 <r_seek+0x127>
mov    -0xc(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0x12c,%edx
call   1030 <recibe@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12b2 <r_seek+0x122>
lea    0xd9e(%rip),%rdi
call   10a0 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12fd <r_seek+0x16d>
jmp    126e <r_seek+0xde>
lea    -0x160(%rbp),%rdi
lea    0xd8c(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1090 <sscanf@plt>
cmpl   $0x0,-0x24(%rbp)
je     12f5 <r_seek+0x165>
mov    -0x24(%rbp),%ecx
mov    0x2cf2(%rip),%rax
mov    %ecx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12fd <r_seek+0x16d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_seek>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x148,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x10(%rsp),%rbp
mov    $0x12c,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe40(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r14d,%ecx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <envia@plt>
cmp    $0xffffffff,%eax
je     1276 <r_seek+0xe6>
mov    %ebx,%edi
mov    $0xbb8,%esi
call   1070 <pollIn@plt>
cmp    $0x1,%eax
jne    1213 <r_seek+0x83>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1282 <r_seek+0xf2>
xor    %eax,%eax
lea    0x10(%rsp),%r14
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
jne    1241 <r_seek+0xb1>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x12c,%edx
call   1030 <recibe@plt>
cmp    $0xffffffff,%eax
jne    1220 <r_seek+0x90>
lea    0xdff(%rip),%rdi
jmp    127d <r_seek+0xed>
lea    0xe09(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1090 <sscanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     126f <r_seek+0xdf>
mov    0x2d6d(%rip),%rcx
mov    %eax,(%rcx)
jmp    1282 <r_seek+0xf2>
mov    0x8(%rsp),%rax
jmp    1289 <r_seek+0xf9>
lea    0xd92(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffffffffffff,%rax
add    $0x148,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"r_seek %ld %d\0A\00"
@.str.1 = [18 x i8] c"r_seek(): envia()\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"r_seek(): pollIn(): timeout\0A\00"
@.str.3 = [19 x i8] c"r_seek(): recibe()\00"
@.str.4 = [7 x i8] c"%d %ld\00"
@errno = global i32 0
define i64 @r_seek(i32 %0, i64 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca [300 x i8]
store i32 %0, i32* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%12 = bitcast [300 x i8]* %11 to i8*
%13 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%14 = load i64, i64* %6
%15 = load i32, i32* %7
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %15)
%17 = load i32, i32* %5
%18 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%19 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @envia(i32 %17, i8* %18, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %3
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i64 -1, i64* %4
br label %55
25: ; preds = %3
%26 = load i32, i32* %5
%27 = call i32 @pollIn(i32 %26, i32 3000)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i64 -1, i64* %4
br label %55
33: ; preds = %25
store i32 0, i32* %8
br label %34
34: ; preds = %45, %33
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i32, i32* %5
%39 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%40 = call i32 @recibe(i32 %38, i8* %39, i32 300)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i64 -1, i64* %4
br label %55
45: ; preds = %37
br label %34
46: ; preds = %34
%47 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%48 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %9, i64* %10)
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = load i32, i32* %9
store i32 %52, i32* @errno
store i64 -1, i64* %4
br label %55
53: ; preds = %46
%54 = load i64, i64* %10
store i64 %54, i64* %4
br label %55
55: ; preds = %53, %51, %43, %30, %23
%56 = load i64, i64* %4
ret i64 %56
}

LLVM IR (-O2):
@.str = [15 x i8] c"r_seek %ld %d\0A\00"
@.str.1 = [18 x i8] c"r_seek(): envia()\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"r_seek(): pollIn(): timeout\0A\00"
@.str.3 = [19 x i8] c"r_seek(): recibe()\00"
@.str.4 = [7 x i8] c"%d %ld\00"
@errno = global i32 0
define i64 @r_seek(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca [300 x i8]
%7 = bitcast i32* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %1, i32 %2)
%11 = call i32 @strlen(i8* %9)
%12 = call i32 @envia(i32 %0, i8* %9, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %37
16: ; preds = %3
%17 = call i32 @pollIn(i32 %0, i32 3000)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %37
22: ; preds = %16, %25
%23 = phi i32 [ %26, %25 ], [ 0, %16 ]
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = call i32 @recibe(i32 %0, i8* %9, i32 300)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %22
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %37
30: ; preds = %22
%31 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %4, i64* %5)
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %30
store i32 %32, i32* @errno
br label %37
35: ; preds = %30
%36 = load i64, i64* %5
br label %37
37: ; preds = %35, %34, %28, %19, %14
%38 = phi i64 [ -1, %14 ], [ -1, %19 ], [ -1, %28 ], [ -1, %34 ], [ %36, %35 ]
ret i64 %38
}