#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;
typedef int /*<<< orphan*/ mode_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
int chmod(char const *, int /*<<< orphan*/);
int chown(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int set_perms(const char *fname, uid_t uid, gid_t gid, mode_t mode) {
  assert(fname);
  if (chmod(fname, mode) == -1)
    return 1;
  if (chown(fname, uid, gid) == -1)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<set_perms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <chmod@plt>
cmp    $0xffffffff,%eax
jne    116f <set_perms+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    119a <set_perms+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <chown@plt>
cmp    $0xffffffff,%eax
jne    1193 <set_perms+0x63>
movl   $0x1,-0x4(%rbp)
jmp    119a <set_perms+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_perms>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <chmod@plt>
cmp    $0xffffffff,%eax
je     1170 <set_perms+0x40>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1040 <chown@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
jmp    1175 <set_perms+0x45>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @set_perms(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i8*, i8** %6
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %6
%13 = load i32, i32* %9
%14 = call i32 @chmod(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 1, i32* %5
br label %25
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = call i32 @chown(i8* %18, i32 %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %5
br label %25
24: ; preds = %17
store i32 0, i32* %5
br label %25
25: ; preds = %24, %23, %16
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
define i32 @set_perms(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @chmod(i8* %0, i32 %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i32 @chown(i8* %0, i32 %1, i32 %2)
%10 = icmp eq i32 %9, -1
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %8, %4
%13 = phi i32 [ 1, %4 ], [ %11, %8 ]
ret i32 %13
}