#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 uint32_t;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strlen(char *);
int remoteGCD(int sock, struct sockaddr_in *pAddr, uint32_t n, uint32_t m,
              uint32_t *pResult) {
  char str[32];
  int i;
  sprintf(str, "gcd %u %u", n, m);
  if (-1 == sendto(sock, str, strlen(str), 0, (struct sockaddr *)pAddr,
                   sizeof(*pAddr)))
    return -1;
  if ((i = recvfrom(sock, str, 32, 0, NULL, NULL)) == -1)
    return -1;
  str[i] = '\0';
  sscanf(str, "%d", pResult);
  return 0;
}


x86 assembly (clang, -O0):
<remoteGCD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe86(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
mov    -0x10(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1040 <sendto@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11cb <remoteGCD+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <remoteGCD+0xd2>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1050 <recvfrom@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    11fe <remoteGCD+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <remoteGCD+0xd2>
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdf4(%rip),%rsi
call   1060 <sscanf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remoteGCD>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe97(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1040 <sendto@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11d3 <remoteGCD+0x83>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x20,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     11d3 <remoteGCD+0x83>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe44(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"gcd %u %u\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @remoteGCD(i32 %0, %struct.sockaddr_in* %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca [32 x i8]
%13 = alloca i32
store i32 %0, i32* %7
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%15 = load i32, i32* %9
%16 = load i32, i32* %10
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i32, i32* %7
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%23 = bitcast %struct.sockaddr_in* %22 to %struct.sockaddr*
%24 = call i32 @sendto(i32 %18, i8* %19, i32 %21, i32 0, %struct.sockaddr* %23, i32 4)
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %27
26: ; preds = %5
store i32 -1, i32* %6
br label %40
27: ; preds = %5
%28 = load i32, i32* %7
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%30 = call i32 @recvfrom(i32 %28, i8* %29, i32 32, i32 0, i32* null, i32* null)
store i32 %30, i32* %13
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -1, i32* %6
br label %40
33: ; preds = %27
%34 = load i32, i32* %13
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%38 = load i32*, i32** %11
%39 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %38)
store i32 0, i32* %6
br label %40
40: ; preds = %33, %32, %26
%41 = load i32, i32* %6
ret i32 %41
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"gcd %u %u\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @remoteGCD(i32 %0, %struct.sockaddr_in* %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3)
%9 = call i32 @strlen(i8* %7)
%10 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%11 = call i32 @sendto(i32 %0, i8* %7, i32 %9, i32 0, %struct.sockaddr* %10, i32 4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %20, label %13
13: ; preds = %5
%14 = call i32 @recvfrom(i32 %0, i8* %7, i32 32, i32 0, i32* null, i32* null)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = sext i32 %14 to i64
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
br label %20
20: ; preds = %13, %5, %16
%21 = phi i32 [ 0, %16 ], [ -1, %5 ], [ -1, %13 ]
ret i32 %21
}