#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 */
scalar_t__ fwrite(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ *getfileparam(char *, int *);
char *luaL_opt_lstr(int /*<<< orphan*/, int /*<<< orphan*/ *, long *);
int /*<<< orphan*/ pushresult(int);
void io_write(void) {
  int arg = 2;
  FILE *f = getfileparam("_OUTPUT", &arg);
  int status = 1;
  char *s;
  long l;
  while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
    status = status && ((long)fwrite(s, 1, l, f) == l);
  pushresult(status);
}


x86 assembly (clang, -O0):
<io_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x2,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <getfileparam@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
call   1040 <luaL_opt_lstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cf <io_write+0x8f>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x29(%rbp)
je     11bf <io_write+0x7f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
cmp    -0x28(%rbp),%rax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <io_write+0x2a>
mov    -0x14(%rbp),%edi
call   1030 <pushresult@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_write>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x2,0x4(%rsp)
lea    0xea9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <getfileparam@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
lea    0x1(%rdi),%eax
mov    %eax,0x4(%rsp)
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1040 <luaL_opt_lstr@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11d2 <io_write+0x92>
lea    0x8(%rsp),%rbx
jmp    11ca <io_write+0x8a>
nopl   0x0(%rax)
mov    0x8(%rsp),%rdx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1060 <fwrite@plt>
cmp    0x8(%rsp),%rax
sete   %al
movzbl %al,%ebp
mov    0x4(%rsp),%edi
lea    0x1(%rdi),%eax
mov    %eax,0x4(%rsp)
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <luaL_opt_lstr@plt>
test   %rax,%rax
je     11d2 <io_write+0x92>
test   %ebp,%ebp
jne    1190 <io_write+0x50>
xor    %eax,%eax
jmp    11ad <io_write+0x6d>
mov    %ebp,%edi
call   1030 <pushresult@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"_OUTPUT\00"
define void @io_write() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 2, i32* %1
%6 = call i32* @getfileparam(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %1)
store i32* %6, i32** %2
store i32 1, i32* %3
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
%10 = call i8* @luaL_opt_lstr(i32 %8, i32* null, i64* %5)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = load i32*, i32** %2
%19 = call i64 @fwrite(i8* %16, i32 1, i64 %17, i32* %18)
%20 = load i64, i64* %5
%21 = icmp eq i64 %19, %20
br label %22
22: ; preds = %15, %12
%23 = phi i1 [ false, %12 ], [ %21, %15 ]
%24 = zext i1 %23 to i32
store i32 %24, i32* %3
br label %7
25: ; preds = %7
%26 = load i32, i32* %3
%27 = call i32 @pushresult(i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"_OUTPUT\00"
define void @io_write() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %1 to i8*
store i32 2, i32* %1
%4 = call i32* @getfileparam(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = bitcast i64* %2 to i8*
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
store i32 %7, i32* %1
%8 = call i8* @luaL_opt_lstr(i32 %6, i32* null, i64* %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %26, label %10
10: ; preds = %0, %19
%11 = phi i8* [ %24, %19 ], [ %8, %0 ]
%12 = phi i32 [ %21, %19 ], [ 1, %0 ]
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i64, i64* %2
%16 = call i64 @fwrite(i8* %11, i32 1, i64 %15, i32* %4)
%17 = load i64, i64* %2
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %14, %10
%20 = phi i1 [ false, %10 ], [ %18, %14 ]
%21 = zext i1 %20 to i32
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
%24 = call i8* @luaL_opt_lstr(i32 %22, i32* null, i64* %2)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %10
26: ; preds = %19, %0
%27 = phi i32 [ 1, %0 ], [ %21, %19 ]
%28 = call i32 @pushresult(i32 %27)
ret void
}