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

/* Variables and functions */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int);
int get(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void shutdown(int, char *, int);
void set(FILE *stream, int value) {
  int new_value;
  rewind(stream);
  if (fprintf(stream, "%d", value) < 0)
    return shutdown(5, "Failed writing to /proc file", 130 - 1);
  new_value = get(stream);
  if (new_value != value)
    return shutdown(5, "We didn't get what we wrote to /proc back", 134 - 1);
}


x86 assembly (clang, -O0):
<set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe9a(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jge    1190 <set+0x50>
mov    $0x5,%edi
lea    0xe82(%rip),%rsi
mov    $0x81,%edx
call   1030 <shutdown@plt>
jmp    11be <set+0x7e>
mov    -0x8(%rbp),%rdi
call   1060 <get@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11be <set+0x7e>
mov    $0x5,%edi
lea    0xe6c(%rip),%rsi
mov    $0x85,%edx
call   1030 <shutdown@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <rewind@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
test   %rax,%rax
js     1176 <set+0x36>
mov    %rbx,%rdi
call   1060 <get@plt>
cmp    %ebp,%eax
jne    1189 <set+0x49>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe86(%rip),%rsi
mov    $0x5,%edi
mov    $0x81,%edx
jmp    119a <set+0x5a>
lea    0xe90(%rip),%rsi
mov    $0x5,%edi
mov    $0x85,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <shutdown@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [29 x i8] c"Failed writing to /proc file\00"
@.str.2 = [42 x i8] c"We didn't get what we wrote to /proc back\00"
define void @set(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = call i32 @rewind(i32* %6)
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = call i64 @fprintf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
br label %20
13: ; preds = %2
%14 = load i32*, i32** %3
%15 = call i32 @get(i32* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %13
br label %20
20: ; preds = %12, %19, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [29 x i8] c"Failed writing to /proc file\00"
@.str.2 = [42 x i8] c"We didn't get what we wrote to /proc back\00"
define void @set(i32* %0, i32 %1) {
%3 = tail call i32 @rewind(i32* %0)
%4 = tail call i64 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %2
tail call void @shutdown(i32 5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %11
7: ; preds = %2
%8 = tail call i32 @get(i32* %0)
%9 = icmp eq i32 %8, %1
br i1 %9, label %11, label %10
10: ; preds = %7
tail call void @shutdown(i32 5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 133)
br label %11
11: ; preds = %7, %10, %6
ret void
}