#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int setuid(int /*<<< orphan*/);
char *strerror(int);
int main(int args, char *argv[]) {
  int status = setuid(0);
  if (status == -1) {
    int errn = errno;
    perror("setuid");
    printf("%s\n", strerror(errn));
    exit(EXIT_FAILURE);
  }
  printf("setuid finished with no errors");
  exit(EXIT_SUCCESS);
}


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)
xor    %edi,%edi
call   1060 <setuid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b9 <main+0x69>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <perror@plt>
mov    -0x18(%rbp),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1070 <setuid@plt>
cmp    $0xffffffff,%eax
jne    119f <main+0x3f>
mov    0x2e6c(%rip),%rax
mov    (%rax),%ebx
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%edi
call   1080 <strerror@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [7 x i8] c"setuid\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [31 x i8] c"setuid finished with no errors\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @setuid(i32 0)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @errno
store i32 %12, i32* %7
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %7
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_SUCCESS
%22 = call i32 @exit(i32 %21)
unreachable
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [7 x i8] c"setuid\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [31 x i8] c"setuid finished with no errors\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @setuid(i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8* @strerror(i32 %6)
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_SUCCESS
%15 = tail call i32 @exit(i32 %14)
unreachable
}