#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*/ prot;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int set_permissoins(int prot) {
  FILE *fp;
  int ret = 0;
  if ((fp = fopen("/tmp/udev_paranoia_protection", "w")) == NULL) {
    return 1;
  }
  if (fwrite(&prot, sizeof(prot), 1, fp) != 1) {
    ret = 1;
  }
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<set_permissoins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xece(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    116f <set_permissoins+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    11a5 <set_permissoins+0x75>
mov    -0x10(%rbp),%rcx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
cmp    $0x1,%eax
je     1196 <set_permissoins+0x66>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_permissoins>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,0x4(%rsp)
lea    0xec2(%rip),%rdi
lea    0xed9(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     117c <set_permissoins+0x4c>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1181 <set_permissoins+0x51>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/tmp/udev_paranoia_protection\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @set_permissoins(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %18
9: ; preds = %1
%10 = load i32*, i32** %4
%11 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 1, i32* %5
br label %14
14: ; preds = %13, %9
%15 = load i32*, i32** %4
%16 = call i32 @fclose(i32* %15)
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %18
18: ; preds = %14, %8
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [30 x i8] c"/tmp/udev_paranoia_protection\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @set_permissoins(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = call i32 @fwrite(i32* %2, i32 4, i32 1, i32* %3)
%7 = icmp ne i32 %6, 1
%8 = zext i1 %7 to i32
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %8, %5 ], [ 1, %1 ]
ret i32 %11
}