#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  printf("Output via regular printf\n");
  write(0, "Output via write (0, ...)\n",
        strlen("Output via write (0, ...)\n"));
  write(1, "Output via write (1, ...)\n",
        strlen("Output via write (1, ...)\n"));
  write(2, "Output via write (2, ...)\n",
        strlen("Output via write (2, ...)\n"));
  close(1);
  open("/tmpfile", 0x0001 | 0x0200);
  write(1, "Output via write (1, ...)\n",
        strlen("Output via write (1, ...)\n"));
  close(1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xe82(%rip),%rsi
call   1030 <write@plt>
lea    0xe91(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe7e(%rip),%rsi
call   1030 <write@plt>
lea    0xe8d(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe7a(%rip),%rsi
call   1030 <write@plt>
mov    $0x1,%edi
call   1060 <close@plt>
lea    0xe7f(%rip),%rdi
mov    $0x201,%esi
call   1070 <open@plt>
lea    0xe38(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe25(%rip),%rsi
call   1030 <write@plt>
mov    $0x1,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xe89(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe89(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe86(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   1060 <close@plt>
lea    0xe79(%rip),%rdi
mov    $0x201,%esi
call   1070 <open@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Output via regular printf\0A\00"
@.str.1 = [27 x i8] c"Output via write (0, ...)\0A\00"
@.str.2 = [27 x i8] c"Output via write (1, ...)\0A\00"
@.str.3 = [27 x i8] c"Output via write (2, ...)\0A\00"
@.str.4 = [9 x i8] c"/tmpfile\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @write(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @write(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @write(i32 2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i32 @close(i32 1)
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 513)
%15 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @write(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @close(i32 1)
%18 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"Output via write (0, ...)\0A\00"
@.str.2 = [27 x i8] c"Output via write (1, ...)\0A\00"
@.str.3 = [27 x i8] c"Output via write (2, ...)\0A\00"
@.str.4 = [9 x i8] c"/tmpfile\00"
@str = [26 x i8] c"Output via regular printf\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @write(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @close(i32 1)
%11 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 513)
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = tail call i32 @close(i32 1)
%15 = tail call i32 @exit(i32 0)
unreachable
}