#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
void update_to_file(int potval) {
  FILE *fp;
  if (potval > 4320)
    potval = 4320;
  fp = fopen("/tmp/pot_value", "w");
  if (fp == NULL) {
    fprintf(stderr, "Can't open "
                    "/tmp/pot_value"
                    "!\n");
    return;
  }
  fprintf(fp, "%d", potval);
  fclose(fp);
}


x86 assembly (clang, -O0):
<update_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x10e0,-0x4(%rbp)
jle    114f <update_to_file+0x1f>
movl   $0x10e0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118e <update_to_file+0x5e>
mov    0x2e68(%rip),%rax
movslq (%rax),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11ac <update_to_file+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_to_file>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeb4(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118d <update_to_file+0x4d>
mov    %rax,%rbx
cmp    $0x10e0,%ebp
mov    $0x10e0,%edx
cmovl  %ebp,%edx
lea    0xeb8(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e4c(%rip),%rax
movslq (%rax),%rcx
lea    0xe73(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/pot_value\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Can't open /tmp/pot_value!\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define void @update_to_file(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 4320
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 4320, i32* %2
br label %7
7: ; preds = %6, %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %22
16: ; preds = %7
%17 = load i32*, i32** %3
%18 = load i32, i32* %2
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %16, %11
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/pot_value\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Can't open /tmp/pot_value!\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define void @update_to_file(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 27, i64 1, i32* %7)
br label %14
9: ; preds = %1
%10 = icmp slt i32 %0, 4320
%11 = select i1 %10, i32 %0, i32 4320
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @fclose(i32* %2)
br label %14
14: ; preds = %9, %4
ret void
}