#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);
int /*<<< orphan*/ printf(char *);
void update_to_file(int potval) {
  FILE *fp;
  if (potval > 4320)
    potval = 4320;
  fp = fopen("/tmp/pot_value", "w");
  if (fp == NULL) {
    printf("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    115f <update_to_file+0x1f>
movl   $0x10e0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <update_to_file+0x52>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <update_to_file+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8d(%rip),%rsi
call   1050 <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   1060 <fopen@plt>
test   %rax,%rax
je     118b <update_to_file+0x4b>
mov    %rax,%rbx
cmp    $0x10e0,%ebp
mov    $0x10e0,%edx
cmovl  %ebp,%edx
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe82(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/tmp/pot_value\00"
@.str.1 = [2 x i8] c"w\00"
@.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 %13
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %19
13: ; preds = %7
%14 = load i32*, i32** %3
%15 = load i32, i32* %2
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
br label %19
19: ; preds = %13, %11
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/tmp/pot_value\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [27 x i8] c"Can't open /tmp/pot_value!\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 %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %11
6: ; preds = %1
%7 = icmp slt i32 %0, 4320
%8 = select i1 %7, i32 %0, i32 4320
%9 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @fclose(i32* %2)
br label %11
11: ; preds = %6, %4
ret void
}