#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 open(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int strlen(char *);
int write(int, char *, int);
int msx_write2(char *fn, int val1, int val2) {
  int fd = open(fn, 1);
  int l, r;
  char num[30];
  if (fd == -1)
    return (0);
  sprintf(num, "%d %d\n", val1, val2);
  r = write(fd, num, l = strlen(num));
  close(fd);
  return (r == l);
}


x86 assembly (clang, -O0):
<msx_write2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1189 <msx_write2+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <msx_write2+0x93>
lea    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe66(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
mov    %edx,-0x20(%rbp)
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msx_write2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    $0x1,%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11b1 <msx_write2+0x61>
mov    %eax,%ebx
lea    0xe89(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
cmp    %ebp,%r14d
sete   %al
jmp    11b3 <msx_write2+0x63>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %d\0A\00"
define i32 @msx_write2(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [30 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = call i32 @open(i8* %12, i32 1)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %33
17: ; preds = %3
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
%22 = load i32, i32* %8
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %9
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %8
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = icmp eq i32 %29, %30
%32 = zext i1 %31 to i32
store i32 %32, i32* %4
br label %33
33: ; preds = %17, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
define i32 @msx_write2(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [30 x i8]
%5 = tail call i32 @open(i8* %0, i32 1)
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %5, -1
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%10 = call i32 @strlen(i8* %6)
%11 = call i32 @write(i32 %5, i8* %6, i32 %10)
%12 = call i32 @close(i32 %5)
%13 = icmp eq i32 %11, %10
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %3, %8
%16 = phi i32 [ %14, %8 ], [ 0, %3 ]
ret i32 %16
}