#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);
int /*<<< orphan*/ rename(char *, char *);
void writeCurr(int curr, int aim) {
  FILE *out;
  out = fopen("/var/run/lock/rotor."
              "curr"
              ".tmp",
              "w");
  if (!out) {
    return;
  }
  fprintf(out, "%d:%d", curr, aim);
  fclose(out);
  rename("/var/run/lock/rotor."
         "curr"
         ".tmp",
         "/var/run/lock/rotor."
         "curr");
}


x86 assembly (clang, -O0):
<writeCurr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xeab(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1175 <writeCurr+0x35>
jmp    11a7 <writeCurr+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe99(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe65(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <rename@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeCurr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xeb0(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1197 <writeCurr+0x57>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe79(%rip),%rdi
lea    0xe97(%rip),%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <rename@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/var/run/lock/rotor.curr.tmp\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"%d:%d\00"
@.str.3 = [25 x i8] c"/var/run/lock/rotor.curr\00"
define void @writeCurr(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 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** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
br label %18
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
%15 = load i32*, i32** %5
%16 = call i32 @fclose(i32* %15)
%17 = call i32 @rename(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %10, %9
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/var/run/lock/rotor.curr.tmp\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"%d:%d\00"
@.str.3 = [25 x i8] c"/var/run/lock/rotor.curr\00"
define void @writeCurr(i32 %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([29 x i8], [29 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 %9, label %5
5: ; preds = %2
%6 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1)
%7 = tail call i32 @fclose(i32* %3)
%8 = tail call i32 @rename(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %9
9: ; preds = %2, %5
ret void
}