#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 */
scalar_t__ close(int);
int strlen(char const *);
int write(int, char const *, int);
int write_something(int fd) {
  int rc;
  const char msg[] = "I Love Linux!!!\n";
  int msg_len = strlen(msg);
  rc = write(fd, msg, msg_len);
  if (rc != msg_len)
    return (0);
  if (close(fd))
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<write_something>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb9(%rip),%al
mov    %al,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1190 <write_something+0x60>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <write_something+0x85>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     11ae <write_something+0x7e>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <write_something+0x85>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_something>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movaps 0xebf(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
jne    117d <write_something+0x4d>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.write_something.msg = [17 x i8] c"I Love Linux!!!\0A\00"
define i32 @write_something(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = bitcast [17 x i8]* %5 to i8*
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %3
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* %6
%13 = call i32 @write(i32 %10, i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = load i32, i32* %6
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 0, i32* %2
br label %24
18: ; preds = %1
%19 = load i32, i32* %3
%20 = call i64 @close(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %2
br label %24
23: ; preds = %18
store i32 1, i32* %2
br label %24
24: ; preds = %23, %22, %17
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@__const.write_something.msg = [17 x i8] c"I Love Linux!!!\0A\00"
define i32 @write_something(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = call i32 @strlen(i8* %3)
%5 = call i32 @write(i32 %0, i8* %3, i32 %4)
%6 = icmp eq i32 %5, %4
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i64 @close(i32 %0)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %7, %1
%12 = phi i32 [ 0, %1 ], [ %10, %7 ]
ret i32 %12
}