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

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ ask_for_flock(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ ftruncate(int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ setup_file_hdr(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void create_sa_file(int *ofd, char *ofile) {
  if ((*ofd = open(ofile, O_CREAT | O_WRONLY,
                   S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
    fprintf(stderr, ("Cannot open %s: %s\n"), ofile, strerror(errno));
    exit(2);
  }
  ask_for_flock(*ofd, 1);
  if (ftruncate(*ofd, 0) < 0) {
    fprintf(stderr, ("Cannot open %s: %s\n"), ofile, strerror(errno));
    exit(2);
  }
  setup_file_hdr(*ofd);
}


x86 assembly (clang, -O0):
<create_sa_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e0c(%rip),%rax
or     (%rax),%esi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    0x2e3a(%rip),%rax
or     (%rax),%edx
mov    0x2e11(%rip),%rax
or     (%rax),%edx
mov    0x2e00(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    1210 <create_sa_file+0xa0>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1030 <ask_for_flock@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
jge    1279 <create_sa_file+0x109>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xd96(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <setup_file_hdr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_sa_file>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rcx
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e23(%rip),%rcx
mov    0x2e4c(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e21(%rip),%rcx
or     (%rcx),%edx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e0a(%rip),%rcx
or     (%rcx),%edx
mov    %rsi,%rdi
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,(%rbx)
test   %eax,%eax
js     11e8 <create_sa_file+0x78>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <ask_for_flock@plt>
mov    (%rbx),%edi
xor    %esi,%esi
call   1040 <ftruncate@plt>
test   %rax,%rax
js     11e8 <create_sa_file+0x78>
mov    (%rbx),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <setup_file_hdr@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfa(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i32 0
define void @create_sa_file(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %5, i32 %8, i32 %15)
%17 = load i32*, i32** %3
store i32 %16, i32* %17
%18 = icmp slt i32 %16, 0
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %2
%27 = load i32*, i32** %3
%28 = load i32, i32* %27
%29 = call i32 @ask_for_flock(i32 %28, i32 1)
%30 = load i32*, i32** %3
%31 = load i32, i32* %30
%32 = call i64 @ftruncate(i32 %31, i32 0)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %4
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %38)
%40 = call i32 @exit(i32 2)
unreachable
41: ; preds = %26
%42 = load i32*, i32** %3
%43 = load i32, i32* %42
%44 = call i32 @setup_file_hdr(i32 %43)
ret void
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i32 0
define void @create_sa_file(i32* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IRGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* %1, i32 %5, i32 %12)
store i32 %13, i32* %0
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %18)
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %2
%22 = tail call i32 @ask_for_flock(i32 %13, i32 1)
%23 = load i32, i32* %0
%24 = tail call i64 @ftruncate(i32 %23, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %29)
%31 = tail call i32 @exit(i32 2)
unreachable
32: ; preds = %21
%33 = load i32, i32* %0
%34 = tail call i32 @setup_file_hdr(i32 %33)
ret void
}