#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 sscanf(char *, char *, int *, int *, int *);
char *strstr(char *, char *);
int find_my_node(char *map, int me) {
  int abs_rank;
  int base, H, L;
  char *p;
  p = map;
  abs_rank = 0;
  while (NULL != (p = strstr(p + 1, ",("))) {
    if (3 != sscanf(p, ",(%d,%d,%d)", &base, &H, &L)) {
      return -1;
    }
    if (me >= abs_rank && me < abs_rank + H * L) {
      return base + (me - abs_rank) / L;
    }
    abs_rank += H * L;
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_my_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
lea    0xeb3(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11ef <find_my_node+0xcf>
mov    -0x30(%rbp),%rdi
lea    0xe94(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x3,%eax
cmp    %ecx,%eax
je     119b <find_my_node+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <find_my_node+0xd6>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     11dd <find_my_node+0xbd>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x24(%rbp),%edx
add    %edx,%ecx
cmp    %ecx,%eax
jge    11dd <find_my_node+0xbd>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <find_my_node+0xd6>
mov    -0x20(%rbp),%eax
imul   -0x24(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    113e <find_my_node+0x1e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_my_node>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
add    $0x1,%rdi
lea    0xec5(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,%rbx
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     11ca <find_my_node+0xaa>
xor    %r12d,%r12d
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%r14
jmp    117e <find_my_node+0x5e>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %rbx,%rdi
lea    0xe92(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,%rbx
mov    %r15d,%r12d
test   %rax,%rax
je     11c5 <find_my_node+0xa5>
mov    %rbx,%rdi
lea    0xe7b(%rip),%rsi
lea    0x14(%rsp),%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1030 <sscanf@plt>
cmp    $0x3,%eax
jne    11c5 <find_my_node+0xa5>
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r15d
imul   %ecx,%r15d
add    %r12d,%r15d
cmp    %ebp,%r12d
jg     1160 <find_my_node+0x40>
cmp    %ebp,%r15d
jle    1160 <find_my_node+0x40>
sub    %r12d,%ebp
mov    %ebp,%eax
cltd
idiv   %ecx
add    0x14(%rsp),%eax
jmp    11ca <find_my_node+0xaa>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c",(\00"
@.str.1 = [12 x i8] c",(%d,%d,%d)\00"
define i32 @find_my_node(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
store i8* %11, i8** %10
store i32 0, i32* %6
br label %12
12: ; preds = %42, %2
%13 = load i8*, i8** %10
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %10
%16 = icmp ne i8* null, %15
br i1 %16, label %17, label %48
17: ; preds = %12
%18 = load i8*, i8** %10
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%20 = icmp ne i32 3, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %3
br label %49
22: ; preds = %17
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = mul nsw i32 %29, %30
%32 = add nsw i32 %28, %31
%33 = icmp slt i32 %27, %32
br i1 %33, label %34, label %42
34: ; preds = %26
%35 = load i32, i32* %7
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = sub nsw i32 %36, %37
%39 = load i32, i32* %9
%40 = sdiv i32 %38, %39
%41 = add nsw i32 %35, %40
store i32 %41, i32* %3
br label %49
42: ; preds = %26, %22
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = mul nsw i32 %43, %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, %45
store i32 %47, i32* %6
br label %12
48: ; preds = %12
store i32 -1, i32* %3
br label %49
49: ; preds = %48, %34, %21
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [3 x i8] c",(\00"
@.str.1 = [12 x i8] c",(%d,%d,%d)\00"
define i32 @find_my_node(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = call i8* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %34, label %12
12: ; preds = %2, %30
%13 = phi i8* [ %32, %30 ], [ %10, %2 ]
%14 = phi i32 [ %22, %30 ], [ 0, %2 ]
%15 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = icmp sle i32 %14, %1
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, %19
%22 = add nsw i32 %21, %14
%23 = icmp sgt i32 %22, %1
%24 = select i1 %18, i1 %23, i1 false
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i32, i32* %3
%27 = sub nsw i32 %1, %14
%28 = sdiv i32 %27, %20
%29 = add nsw i32 %28, %26
br label %34
30: ; preds = %17
%31 = getelementptr inbounds i8, i8* %13, i64 1
%32 = call i8* @strstr(i8* %31, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %12
34: ; preds = %12, %30, %2, %25
%35 = phi i32 [ %29, %25 ], [ -1, %2 ], [ -1, %30 ], [ -1, %12 ]
ret i32 %35
}