#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
void testFormatting(FILE *f) {
  int *ptr;
  ptr = (int *)malloc(sizeof(int));
  fprintf(f, "char(10): \'%10c\'\r\n", 'c');
  fprintf(f, "string(5): \"%5s\"\r\n", "Justin Smith");
  fprintf(f, "pointer(10): \"%10p\"\r\n", ptr);
  fprintf(f, "so far(20): %n", ptr);
  fprintf(f, "\"%20d\"\r\n", *ptr);
  fprintf(f, "octal(10):21: \"%10o\"\r\n", 21);
  fprintf(f, "hex(5):-21: \"%5x\"\r\n", -21);
  fprintf(f, "signed int(10):-21: \"%10d\"\r\n", -21);
  fprintf(f, "unsigned int(20):-21: \"%20u\"\r\n", -21);
  free(ptr);
}


x86 assembly (clang, -O0):
<testFormatting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
mov    $0x63,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xea7(%rip),%rsi
lea    0xeb3(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x15,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0xffffffeb,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0xffffffeb,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
mov    $0xffffffeb,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testFormatting>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
mov    $0x63,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeb2(%rip),%rsi
lea    0xebe(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeba(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edx
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    $0x15,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
mov    $0xffffffeb,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
mov    $0xffffffeb,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
mov    $0xffffffeb,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"char(10): '%10c'\0D\0A\00"
@.str.1 = [19 x i8] c"string(5): \22%5s\22\0D\0A\00"
@.str.2 = [13 x i8] c"Justin Smith\00"
@.str.3 = [22 x i8] c"pointer(10): \22%10p\22\0D\0A\00"
@.str.4 = [15 x i8] c"so far(20): %n\00"
@.str.5 = [9 x i8] c"\22%20d\22\0D\0A\00"
@.str.6 = [23 x i8] c"octal(10):21: \22%10o\22\0D\0A\00"
@.str.7 = [20 x i8] c"hex(5):-21: \22%5x\22\0D\0A\00"
@.str.8 = [29 x i8] c"signed int(10):-21: \22%10d\22\0D\0A\00"
@.str.9 = [31 x i8] c"unsigned int(20):-21: \22%20u\22\0D\0A\00"
define void @testFormatting(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
store i32* %0, i32** %2
%4 = call i64 @malloc(i32 4)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %3
%6 = load i32*, i32** %2
%7 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 99)
%8 = load i32*, i32** %2
%9 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32*, i32** %2
%11 = load i32*, i32** %3
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %2
%14 = load i32*, i32** %3
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** %2
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %2
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 21)
%22 = load i32*, i32** %2
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 -21)
%24 = load i32*, i32** %2
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 -21)
%26 = load i32*, i32** %2
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 -21)
%28 = load i32*, i32** %3
%29 = call i32 @free(i32* %28)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"char(10): '%10c'\0D\0A\00"
@.str.1 = [19 x i8] c"string(5): \22%5s\22\0D\0A\00"
@.str.2 = [13 x i8] c"Justin Smith\00"
@.str.3 = [22 x i8] c"pointer(10): \22%10p\22\0D\0A\00"
@.str.4 = [15 x i8] c"so far(20): %n\00"
@.str.5 = [9 x i8] c"\22%20d\22\0D\0A\00"
@.str.6 = [23 x i8] c"octal(10):21: \22%10o\22\0D\0A\00"
@.str.7 = [20 x i8] c"hex(5):-21: \22%5x\22\0D\0A\00"
@.str.8 = [29 x i8] c"signed int(10):-21: \22%10d\22\0D\0A\00"
@.str.9 = [31 x i8] c"unsigned int(20):-21: \22%20u\22\0D\0A\00"
define void @testFormatting(i32* nocapture %0) {
%2 = tail call i64 @malloc(i32 4)
%3 = inttoptr i64 %2 to i32*
%4 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 99)
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %8)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 21)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 -21)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 -21)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 -21)
%14 = tail call i32 @free(i32* %3)
ret void
}