#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*/ fwrite(char const *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
int strlen(char const *);
int write(int, char const *, int);
void test1(int argc, char **argv) {
  const char *s = "hello world\n";
  int len = strlen(s);
  int ret;
  puts("test1: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  ret = write(1, s, len);
  fwrite(s, len, 1, stdout);
  if (ret != len)
    puts("len != ret");
  else
    puts("len == ret !!");
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e4c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11bd <test1+0x7d>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
jmp    11c9 <test1+0x89>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %eax,%ebx
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    %ebp,%ebx
lea    0xeaf(%rip),%rax
lea    0xe9d(%rip),%rdi
cmove  %rax,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"hello world\0A\00"
@.str.1 = [42 x i8] c"test1: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\00"
@stdout = global i32 0
@.str.2 = [11 x i8] c"len != ret\00"
@.str.3 = [14 x i8] c"len == ret !!\00"
define void @test1(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @write(i32 1, i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = load i32, i32* @stdout
%17 = call i32 @fwrite(i8* %14, i32 %15, i32 1, i32 %16)
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %2
%24 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"hello world\0A\00"
@.str.1 = [42 x i8] c"test1: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\00"
@stdout = global i32 0
@.str.2 = [11 x i8] c"len != ret\00"
@.str.3 = [14 x i8] c"len == ret !!\00"
define void @test1(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%6 = load i32, i32* @stdout
%7 = tail call i32 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3, i32 1, i32 %6)
%8 = icmp eq i32 %5, %3
%9 = select i1 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0)
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
ret void
}