int getbuiltin(char *p) {
  p += strlen("_get");
  while (strncmp(p, " ", 1) == 0)
    p++;
  if (strncmp("uid", p, 3) == 0) {
    printf(2, "%d\n", getuid());
    return 0;
  }
  if (strncmp("gid", p, 3) == 0) {
    printf(2, "%d\n", getgid());
    return 0;
  }
  printf(2, "Invalid _get parameter\n");
  return -1;
}


x86 assembly (clang, -O0):
<getbuiltin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1187 <getbuiltin+0x47>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <getbuiltin+0x18>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11cd <getbuiltin+0x8d>
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122d <getbuiltin+0xed>
mov    -0x10(%rbp),%rsi
lea    0xe32(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1213 <getbuiltin+0xd3>
mov    $0x0,%al
call   1060 <getgid@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122d <getbuiltin+0xed>
mov    $0x2,%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbuiltin>:
push   %rbx
mov    %rdi,%rbx
add    $0x3,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1150 <getbuiltin+0x10>
lea    0xe9f(%rip),%rdi
mov    $0x3,%edx
mov    %rbx,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a4 <getbuiltin+0x64>
lea    0xe8f(%rip),%rdi
mov    $0x3,%edx
mov    %rbx,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
je     11af <getbuiltin+0x6f>
lea    0xe7b(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11cd <getbuiltin+0x8d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getuid@plt>
jmp    11b8 <getbuiltin+0x78>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getgid@plt>
lea    0xe45(%rip),%rsi
mov    $0x2,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"uid\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [4 x i8] c"gid\00"
@.str.4 = [24 x i8] c"Invalid _get parameter\0A\00"
define i32 @getbuiltin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 4
store i8* %5, i8** %3
br label %6
6: ; preds = %10, %1
%7 = load i8*, i8** %3
%8 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %6
13: ; preds = %6
%14 = load i8*, i8** %3
%15 = call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %14, i64 3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 (...) @getuid()
%19 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 0, i32* %2
br label %29
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %21, i64 3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (...) @getgid()
%26 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
store i32 0, i32* %2
br label %29
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %29
29: ; preds = %27, %24, %17
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"uid\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [4 x i8] c"gid\00"
@.str.4 = [24 x i8] c"Invalid _get parameter\0A\00"
define i32 @getbuiltin(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 4
br label %3
3: ; preds = %3, %1
%4 = phi i8* [ %2, %1 ], [ %7, %3 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 32
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %3, label %8
8: ; preds = %3
%9 = tail call i32 @strncmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4, i64 3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 (...) @getuid()
%13 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %22
14: ; preds = %8
%15 = tail call i32 @strncmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4, i64 3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 (...) @getgid()
%19 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %22
20: ; preds = %14
%21 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %17, %11
%23 = phi i32 [ 0, %11 ], [ 0, %17 ], [ -1, %20 ]
ret i32 %23
}