#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ file_write(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int file_write_int_fd(int fd, int val) {
  char buf[20];
  sprintf(buf, "%d", val);
  if (file_write(fd, buf, 20) < 0) {
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<file_write_int_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xec4(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
call   1040 <file_write@plt>
cmp    $0x0,%rax
jge    116d <file_write_int_fd+0x4d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1179 <file_write_int_fd+0x59>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_write_int_fd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%edx
mov    %edi,%ebx
lea    0xece(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <sprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x14,%edx
call   1040 <file_write@plt>
test   %rax,%rax
jns    115a <file_write_int_fd+0x3a>
mov    0x2e88(%rip),%rax
jmp    1161 <file_write_int_fd+0x41>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @file_write_int_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* %5
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %4
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = call i64 @file_write(i32 %10, i8* %11, i32 20)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %18
16: ; preds = %2
%17 = load i32, i32* @EXIT_SUCCESS
store i32 %17, i32* %3
br label %18
18: ; preds = %16, %14
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @file_write_int_fd(i32 %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i64 @file_write(i32 %0, i8* %4, i32 20)
%7 = icmp slt i64 %6, 0
%8 = load i32, i32* @EXIT_FAILURE
%9 = load i32, i32* @EXIT_SUCCESS
%10 = select i1 %7, i32 %8, i32 %9
ret i32 %10
}