#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 write(int, char *, int);
void *parallel_write(void *arg) {
  int fd = (int)(long)arg;
  int i;
  for (i = 0; i < 3; i++) {
    if (write(fd, "w00t", 4) != 4)
      return NULL;
  }
  return (void *)0x667;
}


x86 assembly (clang, -O0):
<parallel_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1171 <parallel_write+0x61>
mov    -0x14(%rbp),%edi
lea    0xec2(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
je     115e <parallel_write+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    117a <parallel_write+0x6a>
jmp    1163 <parallel_write+0x53>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <parallel_write+0x1a>
mov    $0x667,%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallel_write>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    1165 <parallel_write+0x55>
lea    0xecf(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    1165 <parallel_write+0x55>
lea    0xeb7(%rip),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %ecx,%ecx
cmp    $0x4,%eax
mov    $0x667,%eax
cmovne %rcx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"w00t\00"
define i8* @parallel_write(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i32
store i32 %8, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %18, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %4
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %17
16: ; preds = %12
store i8* null, i8** %2
br label %22
17: ; preds = %12
br label %18
18: ; preds = %17
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %9
21: ; preds = %9
store i8* inttoptr (i64 1639 to i8*), i8** %2
br label %22
22: ; preds = %21, %16
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"w00t\00"
define i8* @parallel_write(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%5 = icmp eq i32 %4, 4
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = icmp eq i32 %10, 4
%12 = select i1 %11, i8* inttoptr (i64 1639 to i8*), i8* null
br label %13
13: ; preds = %9, %6, %1
%14 = phi i8* [ null, %1 ], [ null, %6 ], [ %12, %9 ]
ret i8* %14
}