int setbuiltin(char *p) {
  int i;
  p += strlen("_set");
  while (strncmp(p, " ", 1) == 0)
    p++;
  if (strncmp("uid", p, 3) == 0) {
    p += strlen("uid");
    while (strncmp(p, " ", 1) == 0)
      p++;
    i = makeint(p);
    return (setuid(i));
  } else if (strncmp("gid", p, 3) == 0) {
    p += strlen("gid");
    while (strncmp(p, " ", 1) == 0)
      p++;
    i = makeint(p);
    return (setgid(i));
  }
  printf(2, "Invalid _set parameter\n");
  return -1;
}


x86 assembly (clang, -O0):
<setbuiltin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1197 <setbuiltin+0x47>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1168 <setbuiltin+0x18>
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1210 <setbuiltin+0xc0>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11f0 <setbuiltin+0xa0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <setbuiltin+0x71>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <makeint@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1070 <setuid@plt>
mov    %eax,-0x4(%rbp)
jmp    12a8 <setbuiltin+0x158>
mov    -0x10(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1289 <setbuiltin+0x139>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1269 <setbuiltin+0x119>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    123a <setbuiltin+0xea>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <makeint@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1060 <setgid@plt>
mov    %eax,-0x4(%rbp)
jmp    12a8 <setbuiltin+0x158>
jmp    128e <setbuiltin+0x13e>
mov    $0x2,%edi
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setbuiltin>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0x5,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,-0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1160 <setbuiltin+0x10>
lea    -0x2(%rbx),%r14
lea    0xe8b(%rip),%rdi
mov    $0x3,%edx
mov    %r14,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
je     11c0 <setbuiltin+0x70>
lea    0xe77(%rip),%rdi
mov    $0x3,%edx
mov    %r14,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
je     11f0 <setbuiltin+0xa0>
lea    0xe63(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xchg   %ax,%ax
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     11c0 <setbuiltin+0x70>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <makeint@plt>
mov    %eax,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <setuid@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     11f0 <setbuiltin+0xa0>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <makeint@plt>
mov    %eax,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <setgid@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"uid\00"
@.str.2 = [4 x i8] c"gid\00"
@.str.3 = [24 x i8] c"Invalid _set parameter\0A\00"
define i32 @setbuiltin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 4
store i8* %6, i8** %3
br label %7
7: ; preds = %11, %1
%8 = load i8*, i8** %3
%9 = call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
br label %7
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15, i64 3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 3
store i8* %20, i8** %3
br label %21
21: ; preds = %25, %18
%22 = load i8*, i8** %3
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
br label %21
28: ; preds = %21
%29 = load i8*, i8** %3
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @makeint to i32 (i8*, ...)*)(i8* %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = call i32 (i32, ...) bitcast (i32 (...)* @setuid to i32 (i32, ...)*)(i32 %31)
store i32 %32, i32* %2
br label %55
33: ; preds = %14
%34 = load i8*, i8** %3
%35 = call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %34, i64 3)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i64 3
store i8* %39, i8** %3
br label %40
40: ; preds = %44, %37
%41 = load i8*, i8** %3
%42 = call i32 @strncmp(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %3
br label %40
47: ; preds = %40
%48 = load i8*, i8** %3
%49 = call i32 (i8*, ...) bitcast (i32 (...)* @makeint to i32 (i8*, ...)*)(i8* %48)
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = call i32 (i32, ...) bitcast (i32 (...)* @setgid to i32 (i32, ...)*)(i32 %50)
store i32 %51, i32* %2
br label %55
52: ; preds = %33
br label %53
53: ; preds = %52
%54 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %55
55: ; preds = %53, %47, %28
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"uid\00"
@.str.2 = [4 x i8] c"gid\00"
@.str.3 = [24 x i8] c"Invalid _set parameter\0A\00"
define i32 @setbuiltin(i8* %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 %21
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %4, i64 3
br label %13
13: ; preds = %13, %11
%14 = phi i8* [ %12, %11 ], [ %17, %13 ]
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 32
%17 = getelementptr inbounds i8, i8* %14, i64 1
br i1 %16, label %13, label %18
18: ; preds = %13
%19 = tail call i32 (i8*, ...) bitcast (i32 (...)* @makeint to i32 (i8*, ...)*)(i8* %14)
%20 = tail call i32 (i32, ...) bitcast (i32 (...)* @setuid to i32 (i32, ...)*)(i32 %19)
br label %36
21: ; preds = %8
%22 = tail call i32 @strncmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4, i64 3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %4, i64 3
br label %26
26: ; preds = %26, %24
%27 = phi i8* [ %25, %24 ], [ %30, %26 ]
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 32
%30 = getelementptr inbounds i8, i8* %27, i64 1
br i1 %29, label %26, label %31
31: ; preds = %26
%32 = tail call i32 (i8*, ...) bitcast (i32 (...)* @makeint to i32 (i8*, ...)*)(i8* %27)
%33 = tail call i32 (i32, ...) bitcast (i32 (...)* @setgid to i32 (i32, ...)*)(i32 %32)
br label %36
34: ; preds = %21
%35 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 2 to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %31, %18
%37 = phi i32 [ %20, %18 ], [ %33, %31 ], [ -1, %34 ]
ret i32 %37
}