#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 errno;
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stdout;
char *strerror(int);
int main(int argc, char **argv) {
  const char *path = argv[0];
  const char *mode = "ab";
  FILE *fp = fopen(path, mode);
  if (fp == NULL) {
    fprintf(stdout, "%s(%d)\n", strerror(errno), errno);
  }
  int r = fclose(fp);
  if (r != 0) {
    fprintf(stdout, "%s(%d)\n", strerror(errno), errno);
  }
  if (r != 0) {
    fprintf(stdout, "%s(%d)\n", strerror(errno), errno);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bd <main+0x7d>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
mov    0x2e31(%rip),%rax
mov    (%rax),%ecx
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1208 <main+0xc8>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
mov    0x2de6(%rip),%rax
mov    (%rax),%ecx
lea    0xe00(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1247 <main+0x107>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
mov    0x2da7(%rip),%rax
mov    (%rax),%ecx
lea    0xdc1(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118a <main+0x4a>
mov    0x2e73(%rip),%rax
mov    (%rax),%ebp
mov    0x2e72(%rip),%r14
mov    (%r14),%edi
call   1060 <strerror@plt>
mov    (%r14),%ecx
lea    0xe83(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %eax,%eax
je     11e1 <main+0xa1>
mov    0x2e3b(%rip),%r14
mov    (%r14),%ebx
mov    0x2e39(%rip),%rbp
mov    0x0(%rbp),%edi
call   1060 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xe4a(%rip),%r15
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    (%r14),%ebx
mov    0x0(%rbp),%edi
call   1060 <strerror@plt>
mov    0x0(%rbp),%ecx
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ab\00"
@stdout = global i32 0
@.str.1 = [8 x i8] c"%s(%d)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
store i8* %12, i8** %6
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7
%13 = load i8*, i8** %6
%14 = load i8*, i8** %7
%15 = call i32* @fopen(i8* %13, i8* %14)
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stdout
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = load i32, i32* @errno
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22)
br label %24
24: ; preds = %18, %2
%25 = load i32*, i32** %8
%26 = call i32 @fclose(i32* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i32, i32* @stdout
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = load i32, i32* @errno
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33)
br label %35
35: ; preds = %29, %24
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stdout
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = load i32, i32* @errno
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %41, i32 %42)
br label %44
44: ; preds = %38, %35
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"ab\00"
@stdout = global i32 0
@.str.1 = [8 x i8] c"%s(%d)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stdout
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %10)
br label %12
12: ; preds = %6, %2
%13 = tail call i32 @fclose(i32* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = load i32, i32* @stdout
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19)
%21 = load i32, i32* @stdout
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = load i32, i32* @errno
%25 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %24)
br label %26
26: ; preds = %12, %15
ret i32 0
}