#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*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void do_exit(int code) {
  FILE *f = NULL;
  if (!(f = fopen("./e", "wb"))) {
    fprintf(stderr, "%s: cannot open %s for writing: %s\n", "dosrun2", "./e",
            strerror(errno));
    exit(100);
  }
  fprintf(f, "%d\r\n", code);
  if (ferror(f)) {
    fprintf(stderr, "%s: i/o error on %s: %s\n", "dosrun2", "./e",
            strerror(errno));
    exit(100);
  }
  if (fclose(f) < 0) {
    fprintf(stderr, "%s: i/o error on %s: %s\n", "dosrun2", "./e",
            strerror(errno));
    exit(100);
  }
  exit(code);
}


x86 assembly (clang, -O0):
<do_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11da <do_exit+0x7a>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%r8
lea    0xe4c(%rip),%rsi
lea    0xe69(%rip),%rdx
lea    0xe37(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x64,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
mov    -0x4(%rbp),%edx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     124a <do_exit+0xea>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%r8
lea    0xe0d(%rip),%rsi
lea    0xdf9(%rip),%rdx
lea    0xdc7(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x64,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
jge    12a3 <do_exit+0x143>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%r8
lea    0xdb4(%rip),%rsi
lea    0xda0(%rip),%rdx
lea    0xd6e(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x64,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<do_exit>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xe94(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    119d <do_exit+0x3d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe6c(%rip),%rsi
jmp    11ea <do_exit+0x8a>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11cc <do_exit+0x6c>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jns    120e <do_exit+0xae>
mov    0x2e0d(%rip),%rax
mov    (%rax),%ebx
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe4e(%rip),%rsi
lea    0xe3a(%rip),%rdx
lea    0xe08(%rip),%rcx
mov    %ebx,%edi
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x64,%edi
call   1070 <exit@plt>
mov    %ebp,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"./e\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"%s: cannot open %s for writing: %s\0A\00"
@.str.3 = [8 x i8] c"dosrun2\00"
@errno = global i32 0
@.str.4 = [5 x i8] c"%d\0D\0A\00"
@.str.5 = [25 x i8] c"%s: i/o error on %s: %s\0A\00"
define void @do_exit(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
store i32* null, i32** %3
%4 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = icmp ne i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 @exit(i32 100)
unreachable
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = ptrtoint i32* %13 to i32
%15 = load i32, i32* %2
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %3
%18 = call i64 @ferror(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 100)
unreachable
26: ; preds = %12
%27 = load i32*, i32** %3
%28 = call i64 @fclose(i32* %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 100)
unreachable
36: ; preds = %26
%37 = load i32, i32* %2
%38 = call i32 @exit(i32 %37)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"./e\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"%s: cannot open %s for writing: %s\0A\00"
@.str.3 = [8 x i8] c"dosrun2\00"
@errno = global i32 0
@.str.4 = [5 x i8] c"%d\0D\0A\00"
@.str.5 = [25 x i8] c"%s: i/o error on %s: %s\0A\00"
define void @do_exit(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 100)
unreachable
10: ; preds = %1
%11 = ptrtoint i32* %2 to i64
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%14 = tail call i64 @ferror(i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 100)
unreachable
22: ; preds = %10
%23 = tail call i64 @fclose(i32* %2)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 100)
unreachable
31: ; preds = %22
%32 = tail call i32 @exit(i32 %0)
unreachable
}