#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int send_data(int data, int fd) {
  int n = write(fd, "GTK rocks!\n", 11);
  if (n < 0) {
    fputs("write() of 4 bytes failed!\n", stderr);
    close(fd);
    return 1;
  } else {
    close(fd);
    return 0;
  }
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xeb8(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1188 <send_data+0x58>
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1040 <fputs@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1197 <send_data+0x67>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
lea    0xec4(%rip),%rsi
mov    %ebx,%edi
mov    $0xb,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
test   %eax,%eax
jns    1168 <send_data+0x38>
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"GTK rocks!\0A\00"
@.str.1 = [28 x i8] c"write() of 4 bytes failed!\0A\00"
@stderr = global i32 0
define i32 @send_data(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %5
%15 = call i32 @close(i32 %14)
store i32 1, i32* %3
br label %19
16: ; preds = %2
%17 = load i32, i32* %5
%18 = call i32 @close(i32 %17)
store i32 0, i32* %3
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [12 x i8] c"GTK rocks!\0A\00"
@.str.1 = [28 x i8] c"write() of 4 bytes failed!\0A\00"
@stderr = global i32 0
define i32 @send_data(i32 %0, i32 %1) {
%3 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ 1, %5 ], [ 0, %2 ]
%10 = tail call i32 @close(i32 %1)
ret i32 %9
}