#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_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ fe(char *);
int open(char *, int, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void writer(char *b) {
  int fd;
  fd = open("x_one.scratch", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    fe("Issue when trying to open the outfile");
  }
  if (write(fd, b, strlen(b)) == -1) {
    fe("Issue when trying to write to the outfile");
  }
  if (close(fd) == -1) {
    fe("Issue when closing the outfile");
  }
}


x86 assembly (clang, -O0):
<writer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2e8c(%rip),%rax
or     (%rax),%esi
mov    0x2e7b(%rip),%rax
or     (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    0x2e51(%rip),%rax
or     (%rax),%edx
lea    0xe70(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ae <writer+0x5e>
lea    0xe65(%rip),%rdi
call   1060 <fe@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11e8 <writer+0x98>
lea    0xe51(%rip),%rdi
call   1060 <fe@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1205 <writer+0xb5>
lea    0xe5e(%rip),%rdi
call   1060 <fe@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writer>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e5b(%rip),%rax
mov    0x2e94(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
mov    0x2e50(%rip),%rax
mov    0x2e59(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe76(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11a2 <writer+0x52>
lea    0xe71(%rip),%rdi
call   1060 <fe@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11c7 <writer+0x77>
lea    0xe72(%rip),%rdi
call   1060 <fe@plt>
mov    %ebp,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     11da <writer+0x8a>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fe@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"x_one.scratch\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [38 x i8] c"Issue when trying to open the outfile\00"
@.str.2 = [42 x i8] c"Issue when trying to write to the outfile\00"
@.str.3 = [31 x i8] c"Issue when closing the outfile\00"
define void @writer(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @fe(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = load i32, i32* %3
%19 = load i8*, i8** %2
%20 = load i8*, i8** %2
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @fe(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %17
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @fe(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"x_one.scratch\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [38 x i8] c"Issue when trying to open the outfile\00"
@.str.2 = [42 x i8] c"Issue when trying to write to the outfile\00"
@.str.3 = [31 x i8] c"Issue when closing the outfile\00"
define void @writer(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @fe(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = tail call i32 @strlen(i8* %0)
%16 = tail call i32 @write(i32 %10, i8* %0, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @fe(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i32 @close(i32 %10)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @fe(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
ret void
}