#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*/ logputc(char const);
void logputs(const char *str) {
  if (!str) {
    logputs("(null)");
    return;
  }
  for (size_t i = 0; str[i]; i++) {
    logputc(str[i]);
  }
}


x86 assembly (clang, -O0):
<logputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1148 <logputs+0x28>
lea    0xec2(%rip),%rdi
call   1030 <logputs@plt>
jmp    1184 <logputs+0x64>
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1184 <logputs+0x64>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <logputc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1150 <logputs+0x30>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logputs>:
push   %rbx
test   %rdi,%rdi
je     1145 <logputs+0x35>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1143 <logputs+0x33>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <logputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <logputs+0x20>
pop    %rbx
ret
mov    $0x28,%edi
call   1030 <logputc@plt>
mov    $0x6e,%edi
call   1030 <logputc@plt>
mov    $0x75,%edi
call   1030 <logputc@plt>
mov    $0x6c,%edi
call   1030 <logputc@plt>
mov    $0x6c,%edi
call   1030 <logputc@plt>
mov    $0x29,%edi
pop    %rbx
jmp    1030 <logputc@plt>

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

LLVM IR (-O2):
define void @logputs(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %10
3: ; preds = %1
%4 = tail call i32 @logputc(i8 signext 40)
%5 = tail call i32 @logputc(i8 signext 110)
%6 = tail call i32 @logputc(i8 signext 117)
%7 = tail call i32 @logputc(i8 signext 108)
%8 = tail call i32 @logputc(i8 signext 108)
%9 = tail call i32 @logputc(i8 signext 41)
br label %21
10: ; preds = %1
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %10, %13
%14 = phi i8 [ %19, %13 ], [ %11, %10 ]
%15 = phi i64 [ %17, %13 ], [ 0, %10 ]
%16 = tail call i32 @logputc(i8 signext %14)
%17 = add i64 %15, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %13
21: ; preds = %13, %3, %10
ret void
}