#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*/ do_printf(char *, char *, int *);
int /*<<< orphan*/ putchar(char);
printf(char *fmt, int data) {
  char buf[1024], *p;
  p = buf;
  do_printf(buf, fmt, &data);
  while (*p) {
    if (*p == '\n')
      putchar('\r');
    putchar(*p++);
  }
}


x86 assembly (clang, -O0):
<printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <do_printf@plt>
mov    -0x428(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a3 <printf+0x83>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1181 <printf+0x61>
mov    $0xd,%edi
call   1030 <putchar@plt>
mov    -0x428(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x428(%rbp)
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1154 <printf+0x34>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf>:
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%rax
mov    %esi,0xc(%rsp)
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <do_printf@plt>
jmp    1169 <printf+0x49>
cs nopw 0x0(%rax,%rax,1)
mov    $0xd,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1150 <printf+0x30>
test   %al,%al
jne    115d <printf+0x3d>
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @printf(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8* %8, i8** %7
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @do_printf(i8* %9, i8* %10, i32* %5)
br label %12
12: ; preds = %23, %2
%13 = load i8*, i8** %7
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @putchar(i8 signext 13)
br label %23
23: ; preds = %21, %16
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
%26 = load i8, i8* %24
%27 = call i32 @putchar(i8 signext %26)
br label %12
28: ; preds = %12
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @printf(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
store i32 %1, i32* %3
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @do_printf(i8* %5, i8* %0, i32* %3)
br label %7
7: ; preds = %13, %2
%8 = phi i8* [ %5, %2 ], [ %15, %13 ]
%9 = load i8, i8* %8
switch i8 %9, label %13 [
i8 0, label %17
i8 10, label %10
]
10: ; preds = %7
%11 = call i32 @putchar(i8 signext 13)
%12 = load i8, i8* %8
br label %13
13: ; preds = %7, %10
%14 = phi i8 [ %9, %7 ], [ %12, %10 ]
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = call i32 @putchar(i8 signext %14)
br label %7
17: ; preds = %7
ret i32 undef
}