#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__ EINTR;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
size_t strlen(char const *);
int write(int, char const *, size_t);
int just_print(int fd, const char *msg) {
  size_t to_write = strlen(msg);
  while (to_write) {
    int res = write(fd, msg, to_write);
    if (res < 0) {
      if (errno == EINTR)
        continue;
      return 0;
    }
    assert((size_t)res <= to_write);
    to_write -= res;
  }
  return 1;
}


x86 assembly (clang, -O0):
<just_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c8 <just_print+0x98>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    119f <just_print+0x6f>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
jne    1193 <just_print+0x63>
jmp    114c <just_print+0x1c>
movl   $0x0,-0x4(%rbp)
jmp    11cf <just_print+0x9f>
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <just_print+0x1c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<just_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11a4 <just_print+0x74>
mov    %rax,%rbp
mov    0x2e82(%rip),%r12
mov    0x2e73(%rip),%r13
jmp    1185 <just_print+0x55>
nopw   0x0(%rax,%rax,1)
mov    %eax,%eax
xor    %edi,%edi
sub    %rax,%rbp
setae  %dil
call   1050 <assert@plt>
test   %rbp,%rbp
je     11a4 <just_print+0x74>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
test   %eax,%eax
jns    1170 <just_print+0x40>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1180 <just_print+0x50>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @just_print(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %6
br label %10
10: ; preds = %26, %24, %2
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i64, i64* %6
%17 = call i32 @write(i32 %14, i8* %15, i64 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i64, i64* @errno
%22 = load i64, i64* @EINTR
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
br label %10
25: ; preds = %20
store i32 0, i32* %3
br label %38
26: ; preds = %13
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = load i64, i64* %6
%30 = icmp ule i64 %28, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = load i64, i64* %6
%36 = sub i64 %35, %34
store i64 %36, i64* %6
br label %10
37: ; preds = %10
store i32 1, i32* %3
br label %38
38: ; preds = %37, %25
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @just_print(i32 %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2, %19
%6 = phi i64 [ %20, %19 ], [ %3, %2 ]
%7 = tail call i32 @write(i32 %0, i8* %1, i64 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br i1 %12, label %19, label %22
13: ; preds = %5
%14 = zext i32 %7 to i64
%15 = icmp uge i64 %6, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = sub i64 %6, %14
br label %19
19: ; preds = %9, %13
%20 = phi i64 [ %18, %13 ], [ %6, %9 ]
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %19, %9, %2
%23 = phi i32 [ 1, %2 ], [ 0, %9 ], [ 1, %19 ]
ret i32 %23
}