#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 read(int, char *, int);
int /*<<< orphan*/ usleep(int);
int write(int, unsigned int *, int);
int retrieveValue(int call, int *pointfile) {
  unsigned int cmd[16];
  cmd[0] = call;
  cmd[1] = 1;
  cmd[2] = 2;
  cmd[3] = 3;
  cmd[4] = 4;
  cmd[5] = 5;
  cmd[6] = 6;
  cmd[7] = 7;
  cmd[8] = 8;
  cmd[9] = 9;
  cmd[10] = 10;
  if (write(*pointfile, cmd, 11) == 11) {
    usleep(10000);
    char buf[3];
    if (read(*pointfile, buf, 2) == 2) {
      int resultant = buf[0] << 8 | buf[1];
      return resultant;
    } else {
      return -1;
    }
  }
}


x86 assembly (clang, -O0):
<retrieveValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x50(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x2,-0x48(%rbp)
movl   $0x3,-0x44(%rbp)
movl   $0x4,-0x40(%rbp)
movl   $0x5,-0x3c(%rbp)
movl   $0x6,-0x38(%rbp)
movl   $0x7,-0x34(%rbp)
movl   $0x8,-0x30(%rbp)
movl   $0x9,-0x2c(%rbp)
movl   $0xa,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xb,%eax
jne    11f1 <retrieveValue+0xc1>
mov    $0x2710,%edi
call   1050 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x53(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
cmp    $0x2,%eax
jne    11ea <retrieveValue+0xba>
movsbl -0x53(%rbp),%eax
shl    $0x8,%eax
movsbl -0x52(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <retrieveValue+0xc1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retrieveValue>:
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
mov    %edi,0x10(%rsp)
movaps 0xebd(%rip),%xmm0
movups %xmm0,0x14(%rsp)
movaps 0xec1(%rip),%xmm0
movups %xmm0,0x24(%rsp)
movabs $0xa00000009,%rax
mov    %rax,0x34(%rsp)
mov    (%rsi),%edi
lea    0x10(%rsp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %eax,%ecx
cmp    $0xb,%ecx
jne    11b0 <retrieveValue+0x80>
mov    $0x2710,%edi
call   1050 <usleep@plt>
mov    (%rbx),%edi
lea    0xd(%rsp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
movsbl 0xd(%rsp),%ecx
shl    $0x8,%ecx
movsbl 0xe(%rsp),%edx
or     %ecx,%edx
cmp    $0x2,%eax
mov    $0xffffffff,%eax
cmove  %edx,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @retrieveValue(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [16 x i32]
%7 = alloca [3 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = load i32, i32* %4
%10 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
store i32 %9, i32* %10
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 1
store i32 1, i32* %11
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 2
store i32 2, i32* %12
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 3
store i32 3, i32* %13
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 4
store i32 4, i32* %14
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 5
store i32 5, i32* %15
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 6
store i32 6, i32* %16
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 7
store i32 7, i32* %17
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 8
store i32 8, i32* %18
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 9
store i32 9, i32* %19
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 10
store i32 10, i32* %20
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%24 = call i32 @write(i32 %22, i32* %23, i32 11)
%25 = icmp eq i32 %24, 11
br i1 %25, label %26, label %44
26: ; preds = %2
%27 = call i32 @usleep(i32 10000)
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 2)
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %43
33: ; preds = %26
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = shl i32 %36, 8
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = or i32 %37, %40
store i32 %41, i32* %8
%42 = load i32, i32* %8
store i32 %42, i32* %3
br label %44
43: ; preds = %26
store i32 -1, i32* %3
br label %44
44: ; preds = %33, %43, %2
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @retrieveValue(i32 %0, i32* nocapture %1) {
%3 = alloca [16 x i32]
%4 = alloca [3 x i8]
%5 = bitcast [16 x i32]* %3 to i8*
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
store i32 %0, i32* %6
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 1
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32>* %8
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 5
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, <4 x i32>* %10
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 9
store i32 9, i32* %11
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 10
store i32 10, i32* %12
%13 = load i32, i32* %1
%14 = call i32 @write(i32 %13, i32* %6, i32 11)
%15 = icmp eq i32 %14, 11
br i1 %15, label %16, label %30
16: ; preds = %2
%17 = tail call i32 @usleep(i32 10000)
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* %1
%20 = call i32 @read(i32 %19, i8* %18, i32 2)
%21 = icmp eq i32 %20, 2
%22 = load i8, i8* %18
%23 = sext i8 %22 to i32
%24 = shl nsw i32 %23, 8
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = or i32 %24, %27
%29 = select i1 %21, i32 %28, i32 -1
br label %30
30: ; preds = %2, %16
%31 = phi i32 [ %29, %16 ], [ undef, %2 ]
ret i32 %31
}