#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*/ __wrap_write(int, char *, int /*<<< orphan*/);
scalar_t__ sprintf(char *, char *, int, double, double);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  int ret = 42;
  char buf[1024];
  while (ret == 42) {
    ret += sprintf(buf, "hello world: %d\n", ret, 1.0 / 0.0, 3.5);
    __wrap_write(1, buf, strlen(buf));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2a,-0x8(%rbp)
cmpl   $0x2a,-0x8(%rbp)
jne    11b8 <main+0x88>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xeac(%rip),%rsi
movsd  0xe94(%rip),%xmm0
movsd  0xe94(%rip),%xmm1
call   1040 <sprintf@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1050 <__wrap_write@plt>
jmp    1149 <main+0x19>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xecd(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x2a,%edx
movsd  0xe9d(%rip),%xmm0
movsd  0xe9d(%rip),%xmm1
call   1040 <sprintf@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <__wrap_write@plt>
test   %ebx,%ebx
je     1150 <main+0x20>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"hello world: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 42, i32* %2
br label %4
4: ; preds = %7, %0
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 42
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i64 @sprintf(i8* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9, double 0x7FF0000000000000, double 3.500000e+00)
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, %10
%14 = trunc i64 %13 to i32
store i32 %14, i32* %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @__wrap_write(i32 1, i8* %15, i32 %17)
br label %4
19: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"hello world: %d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %3
%4 = call i64 @sprintf(i8* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 42, double 0x7FF0000000000000, double 3.500000e+00)
%5 = trunc i64 %4 to i32
%6 = call i32 @strlen(i8* %2)
%7 = call i32 @__wrap_write(i32 1, i8* %2, i32 %6)
%8 = icmp eq i32 %5, 0
br i1 %8, label %3, label %9
9: ; preds = %3
ret i32 0
}