#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 */
struct s_map {
  int dummy;
};

/* Variables and functions */
int mapAddReturnID(struct s_map *, void const *, void const *);
int mapGetKeyID(struct s_map *, void const *);
int /*<<< orphan*/ mapSetValueByID(struct s_map *, int, void const *);
int mapSetReturnID(struct s_map *map, const void *key, const void *value) {
  int ret = mapAddReturnID(map, key, value);
  if (ret < 0) {
    ret = mapGetKeyID(map, key);
    if (ret < 0) {
      return -1;
    } else {
      mapSetValueByID(map, ret, value);
      return ret;
    }
  } else {
    return ret;
  }
}


x86 assembly (clang, -O0):
<mapSetReturnID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <mapAddReturnID@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a3 <mapSetReturnID+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <mapGetKeyID@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1188 <mapSetReturnID+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <mapSetReturnID+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <mapSetValueByID@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <mapSetReturnID+0x79>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapSetReturnID>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1050 <mapAddReturnID@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1170 <mapSetReturnID+0x40>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <mapGetKeyID@plt>
test   %eax,%eax
js     116b <mapSetReturnID+0x3b>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <mapSetValueByID@plt>
jmp    1170 <mapSetReturnID+0x40>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.s_map = type { i32 }
define i32 @mapSetReturnID(%struct.s_map* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.s_map*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.s_map* %0, %struct.s_map** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load %struct.s_map*, %struct.s_map** %5
%10 = load i8*, i8** %6
%11 = load i8*, i8** %7
%12 = call i32 @mapAddReturnID(%struct.s_map* %9, i8* %10, i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %3
%16 = load %struct.s_map*, %struct.s_map** %5
%17 = load i8*, i8** %6
%18 = call i32 @mapGetKeyID(%struct.s_map* %16, i8* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %4
br label %30
22: ; preds = %15
%23 = load %struct.s_map*, %struct.s_map** %5
%24 = load i32, i32* %8
%25 = load i8*, i8** %7
%26 = call i32 @mapSetValueByID(%struct.s_map* %23, i32 %24, i8* %25)
%27 = load i32, i32* %8
store i32 %27, i32* %4
br label %30
28: ; preds = %3
%29 = load i32, i32* %8
store i32 %29, i32* %4
br label %30
30: ; preds = %28, %22, %21
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.s_map = type { i32 }
define i32 @mapSetReturnID(%struct.s_map* %0, i8* %1, i8* %2) {
%4 = tail call i32 @mapAddReturnID(%struct.s_map* %0, i8* %1, i8* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i32 @mapGetKeyID(%struct.s_map* %0, i8* %1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @mapSetValueByID(%struct.s_map* %0, i32 %7, i8* %2)
br label %11
11: ; preds = %3, %6, %9
%12 = phi i32 [ %7, %9 ], [ -1, %6 ], [ %4, %3 ]
ret i32 %12
}