#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char const *, char *);
char *strrchr(char *, char);
int system(char const *);
int main(int argc, char **argv) {
  const char *cmd;
  const char *name = strrchr(argv[0], '/');
  if (name)
    ++name;
  else
    name = argv[0];
  if (!strcmp(name, "mount-tmpfs")) {
    cmd = "/usr/sbin/mount -F tmpfs -o size=768m tmpfs "
          "/export/home/wandisco/buildbot/slave/svn-sparc-solaris/obj/"
          "subversion/tests/";
  } else if (!strcmp(name, "umount-tmpfs")) {
    cmd = "/usr/sbin/umount "
          "/export/home/wandisco/buildbot/slave/svn-sparc-solaris/obj/"
          "subversion/tests/";
  } else {
    fprintf(stderr, "command not recognised\n");
    return -1;
  }
  if (setuid(0)) {
    fprintf(stderr, "setuid failed\n");
    return -1;
  }
  return system(cmd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1197 <main+0x47>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <main+0x7b>
lea    0xe3e(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    121a <main+0xca>
mov    -0x20(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f4 <main+0xa4>
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1215 <main+0xc5>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xee0(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <main+0x108>
jmp    121a <main+0xca>
xor    %edi,%edi
call   1070 <setuid@plt>
cmp    $0x0,%rax
je     124c <main+0xfc>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xec1(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <main+0x108>
mov    -0x18(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%r14
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r14,%rbx
lea    0xf04(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11a7 <main+0x57>
lea    0xef0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b0 <main+0x60>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xf3f(%rip),%rsi
jmp    11d3 <main+0x83>
lea    0xe52(%rip),%rbx
jmp    11b7 <main+0x67>
lea    0xecf(%rip),%rbx
xor    %edi,%edi
call   1070 <setuid@plt>
test   %rax,%rax
je     11e5 <main+0x95>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xf29(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <system@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"mount-tmpfs\00"
@.str.1 = [121 x i8] c"/usr/sbin/mount -F tmpfs -o size=768m tmpfs /export/home/wandisco/buildbot/slave/svn-sparc-solaris/obj/subversion/tests/\00"
@.str.2 = [13 x i8] c"umount-tmpfs\00"
@.str.3 = [94 x i8] c"/usr/sbin/umount /export/home/wandisco/buildbot/slave/svn-sparc-solaris/obj/subversion/tests/\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"command not recognised\0A\00"
@.str.5 = [15 x i8] c"setuid failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %7
br label %21
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
store i8* %20, i8** %7
br label %21
21: ; preds = %17, %14
%22 = load i8*, i8** %7
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
store i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %35
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %26
store i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %34
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
34: ; preds = %30
br label %35
35: ; preds = %34, %25
%36 = call i64 @setuid(i32 0)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = call i32 @system(i8* %42)
store i32 %43, i32* %3
br label %44
44: ; preds = %41, %38, %31
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [12 x i8] c"mount-tmpfs\00"
@.str.1 = [121 x i8] c"/usr/sbin/mount -F tmpfs -o size=768m tmpfs /export/home/wandisco/buildbot/slave/svn-sparc-solaris/obj/subversion/tests/\00"
@.str.2 = [13 x i8] c"umount-tmpfs\00"
@.str.3 = [94 x i8] c"/usr/sbin/umount /export/home/wandisco/buildbot/slave/svn-sparc-solaris/obj/subversion/tests/\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"command not recognised\0A\00"
@.str.5 = [15 x i8] c"setuid failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = getelementptr inbounds i8, i8* %4, i64 1
%7 = select i1 %5, i8* %3, i8* %6
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %7, i8* dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %25
16: ; preds = %10, %2
%17 = phi i8* [ getelementptr inbounds ([121 x i8], [121 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([94 x i8], [94 x i8]* @.str.3, i64 0, i64 0), %10 ]
%18 = tail call i64 @setuid(i32 0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %25
23: ; preds = %16
%24 = tail call i32 @system(i8* %17)
br label %25
25: ; preds = %23, %20, %13
%26 = phi i32 [ -1, %13 ], [ -1, %20 ], [ %24, %23 ]
ret i32 %26
}