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

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void changeOwner(char *file) {
  uid_t uid = getuid();
  uid_t gid = getgid();
  if (chown(file, uid, gid) != 0) {
    if (errno == ENOENT)
      fprintf(stderr, "gpio: Warning: File not present: %s\n", file);
    else {
      fprintf(stderr, "gpio: Unable to change ownership of %s: %s\n", file,
              strerror(errno));
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<changeOwner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getgid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <chown@plt>
cmp    $0x0,%rax
je     121d <changeOwner+0xbd>
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
jne    11d3 <changeOwner+0x73>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1218 <changeOwner+0xb8>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    121d <changeOwner+0xbd>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeOwner>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getgid@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <chown@plt>
test   %rax,%rax
je     11bf <changeOwner+0x5f>
mov    0x2e4a(%rip),%rax
mov    (%rax),%rdi
mov    0x2e30(%rip),%rax
mov    0x2e41(%rip),%rcx
mov    (%rcx),%ebp
cmp    (%rax),%rdi
jne    11c6 <changeOwner+0x66>
lea    0xe53(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
call   1080 <strerror@plt>
lea    0xe53(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"gpio: Warning: File not present: %s\0A\00"
@.str.1 = [44 x i8] c"gpio: Unable to change ownership of %s: %s\0A\00"
define void @changeOwner(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @getuid()
store i32 %5, i32* %3
%6 = call i32 (...) @getgid()
store i32 %6, i32* %4
%7 = load i8*, i8** %2
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i64 @chown(i8* %7, i32 %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %1
%13 = load i64, i64* @errno
%14 = load i64, i64* @ENOENT
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %27
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %16
br label %28
28: ; preds = %27, %1
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"gpio: Warning: File not present: %s\0A\00"
@.str.1 = [44 x i8] c"gpio: Unable to change ownership of %s: %s\0A\00"
define void @changeOwner(i8* %0) {
%2 = tail call i32 (...) @getuid()
%3 = tail call i32 (...) @getgid()
%4 = tail call i64 @chown(i8* %0, i32 %2, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp eq i64 %7, %8
%10 = load i32, i32* @stderr
br i1 %9, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
13: ; preds = %6
%14 = tail call i8* @strerror(i64 %7)
%15 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11, %1
ret void
}