#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*/ err_sys(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fwide(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int ret = 0;
  FILE *fp = fopen("abc.txt", "w+");
  if (fp == 0)
    err_sys("fopen failed");
  ret = fwide(fp, 0);
  printf("fwide = %d\n", ret);
  fprintf(fp, "fwide = %d\n", ret);
  ret = fwide(fp, 0);
  printf("fwide = %d\n", ret);
  fprintf(fp, "fwide = %d\n", ret);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <main+0x4b>
lea    0xe65(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <fwide@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe42(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <fwide@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe12(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118b <main+0x2b>
lea    0xe85(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fwide@plt>
mov    %eax,%ebp
lea    0xe7a(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fwide@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"abc.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@.str.3 = [12 x i8] c"fwide = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32*, i32** %7
%15 = call i32 @fwide(i32* %14, i32 0)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %7
%19 = load i32, i32* %6
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %7
%22 = call i32 @fwide(i32* %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %7
%26 = load i32, i32* %6
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"abc.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@.str.3 = [12 x i8] c"fwide = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @fwide(i32* %3, i32 0)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%11 = tail call i32 @fwide(i32* %3, i32 0)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%14 = tail call i32 @fclose(i32* %3)
ret i32 0
}