#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 getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pthread_exit(void *);
int setuid(int);
void *setuid_124(void *unused) {
  int status;
  status = setuid(124);
  if (status < 0) {
    perror("setuid");
    pthread_exit((void *)-1);
  }
  if (getuid() != 124) {
    perror("getuid");
    pthread_exit((void *)-1);
  }
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<setuid_124>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x7c,%edi
call   1060 <setuid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117b <setuid_124+0x3b>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffffffffffff,%rdi
call   1040 <pthread_exit@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x7c,%eax
je     11a3 <setuid_124+0x63>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffffffffffff,%rdi
call   1040 <pthread_exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setuid_124>:
push   %rax
mov    $0x7c,%edi
call   1060 <setuid@plt>
test   %eax,%eax
js     1163 <setuid_124+0x23>
xor    %eax,%eax
call   1030 <getuid@plt>
cmp    $0x7c,%eax
jne    117d <setuid_124+0x3d>
xor    %edi,%edi
pop    %rax
jmp    1040 <pthread_exit@plt>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffffffffffff,%rdi
call   1040 <pthread_exit@plt>
jmp    114f <setuid_124+0xf>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffffffffffff,%rdi
call   1040 <pthread_exit@plt>
jmp    115b <setuid_124+0x1b>

LLVM IR (-O0):
@.str = [7 x i8] c"setuid\00"
@.str.1 = [7 x i8] c"getuid\00"
define i8* @setuid_124(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @setuid(i32 124)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %11
11: ; preds = %8, %1
%12 = call i32 (...) @getuid()
%13 = icmp ne i32 %12, 124
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %17
17: ; preds = %14, %11
%18 = call i32 @pthread_exit(i8* null)
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@.str = [7 x i8] c"setuid\00"
@.str.1 = [7 x i8] c"getuid\00"
define noalias i8* @setuid_124(i8* nocapture readnone %0) {
%2 = tail call i32 @setuid(i32 124)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %7
7: ; preds = %4, %1
%8 = tail call i32 (...) @getuid()
%9 = icmp eq i32 %8, 124
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %13
13: ; preds = %10, %7
%14 = tail call i32 @pthread_exit(i8* null)
ret i8* undef
}