#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 scalar_t__ u_int16_t;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ m_peer_call_id;
typedef int /*<<< orphan*/ m_call_id;
typedef int /*<<< orphan*/ gre;

/* Variables and functions */
int read(int, char *, int);
int write(int, char *, int);
int get_call_id(int sock, pid_t gre, u_int16_t *call_id,
                u_int16_t *peer_call_id) {
  u_int16_t m_call_id, m_peer_call_id;
  int rc;
  rc = write(sock, (char *)&gre, sizeof(gre));
  if (rc != sizeof(gre))
    return -1;
  ;
  rc = read(sock, (char *)&m_call_id, sizeof(m_call_id));
  if (rc != sizeof(m_call_id))
    return -1;
  rc = read(sock, (char *)&m_peer_call_id, sizeof(m_peer_call_id));
  if (rc != sizeof(m_peer_call_id))
    return -1;

  ;
  *call_id = m_call_id;
  *peer_call_id = m_peer_call_id;
  return 0;
}


x86 assembly (clang, -O0):
<get_call_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x4,%rax
je     1164 <get_call_id+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <get_call_id+0xbd>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x8,%rax
je     1192 <get_call_id+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <get_call_id+0xbd>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x8,%rax
je     11c0 <get_call_id+0xa0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <get_call_id+0xbd>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_call_id>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%ebx
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    $0xffffffff,%ebp
cmp    $0x4,%eax
jne    118d <get_call_id+0x6d>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1040 <read@plt>
cmp    $0x8,%eax
jne    118d <get_call_id+0x6d>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1040 <read@plt>
cmp    $0x8,%eax
jne    118d <get_call_id+0x6d>
mov    0x10(%rsp),%rax
mov    %rax,(%r15)
mov    0x8(%rsp),%rax
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_call_id(i32 %0, i32 %1, i64* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i32 %1, i32* %5
%8 = bitcast i64* %6 to i8*
%9 = bitcast i64* %7 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 @write(i32 %0, i8* %10, i32 4)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %22
13: ; preds = %4
%14 = call i32 @read(i32 %0, i8* %8, i32 8)
%15 = icmp eq i32 %14, 8
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = call i32 @read(i32 %0, i8* %9, i32 8)
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i64, i64* %6
store i64 %20, i64* %2
%21 = load i64, i64* %7
store i64 %21, i64* %3
br label %22
22: ; preds = %16, %13, %4, %19
%23 = phi i32 [ 0, %19 ], [ -1, %4 ], [ -1, %13 ], [ -1, %16 ]
ret i32 %23
}