#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 */
typedef int uid_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int getuid();
int /*<<< orphan*/ printf(char *, ...);
uid_t getuid_test(void) {
  uid_t uid;
  int save_errno;
  printf("getuid():\n");
  fflush(NULL);
  uid = getuid();
  save_errno = errno;
  printf("\t\tret = %u\n", uid);
  printf("\tSucceeded Phase 1\n");
  errno = save_errno;
  return uid;
}


x86 assembly (clang, -O0):
<getuid_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    0x2e52(%rip),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getuid_test>:
push   %rbp
push   %r14
push   %rbx
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%ebx
mov    0x2e79(%rip),%r14
mov    (%r14),%ebp
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"getuid():\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %u\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
define i32 @getuid_test() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @fflush(i32* null)
%5 = call i32 (...) @getuid()
store i32 %5, i32* %1
%6 = load i32, i32* @errno
store i32 %6, i32* %2
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %2
store i32 %10, i32* @errno
%11 = load i32, i32* %1
ret i32 %11
}

LLVM IR (-O2):
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %u\0A\00"
@str = [10 x i8] c"getuid():\00"
@str.3 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @getuid_test() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @fflush(i32* null)
%3 = tail call i32 (...) @getuid()
%4 = load i32, i32* @errno
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
store i32 %4, i32* @errno
ret i32 %3
}