#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*/ *);
scalar_t__ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *);
void overwrite() {
  FILE *f = fopen(".otpasswd.lck", "w");
  if (!f) {
    printf("Unable to open for overwrite\n");
    return;
  }
  fprintf(f, "Dupablada\n");
  if (fflush(f) != 0) {
    printf("Unable to fflush\n");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<overwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118b <overwrite+0x3b>
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
jmp    11c3 <overwrite+0x73>
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fflush@plt>
cmp    $0x0,%rax
je     11ba <overwrite+0x6a>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overwrite>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a7 <overwrite+0x57>
mov    %rax,%rbx
lea    0xe9d(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fflush@plt>
test   %rax,%rax
je     119e <overwrite+0x4e>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <fclose@plt>
lea    0xe6d(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [14 x i8] c".otpasswd.lck\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [30 x i8] c"Unable to open for overwrite\0A\00"
@.str.3 = [11 x i8] c"Dupablada\0A\00"
@.str.4 = [18 x i8] c"Unable to fflush\0A\00"
define void @overwrite() {
%1 = alloca i32*
%2 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %2, i32** %1
%3 = load i32*, i32** %1
%4 = icmp ne i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %18
7: ; preds = %0
%8 = load i32*, i32** %1
%9 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%10 = load i32*, i32** %1
%11 = call i64 @fflush(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
br label %18
18: ; preds = %15, %5
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c".otpasswd.lck\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [11 x i8] c"Dupablada\0A\00"
@str = [29 x i8] c"Unable to open for overwrite\00"
@str.5 = [17 x i8] c"Unable to fflush\00"
define void @overwrite() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %13
5: ; preds = %0
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 10, i64 1, i32* %1)
%7 = tail call i64 @fflush(i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = tail call i32 @fclose(i32* %1)
br label %13
13: ; preds = %11, %3
ret void
}