#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*/ puts(char *);
scalar_t__ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
int main(void) {
  char buf[100];
  int result = 0;
  if (sprintf(buf, "%.0ls", L"foo") != 0 || strlen(buf) != 0) {
    puts("sprintf (buf, \"%.0ls\", L\"foo\") produced some output\n");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xeac(%rip),%rsi
lea    0xee1(%rip),%rdx
call   1050 <sprintf@plt>
cmp    $0x0,%rax
jne    117d <main+0x4d>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1190 <main+0x60>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x74(%rbp)
mov    -0x74(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
lea    0xed5(%rip),%rsi
lea    0xf0a(%rip),%rdx
mov    %rsp,%rdi
call   1040 <sprintf@plt>
test   %rax,%rax
jne    114c <main+0x2c>
xor    %eax,%eax
cmpb   $0x0,(%rsp)
jne    114c <main+0x2c>
add    $0x68,%rsp
ret
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%.0ls\00"
@.str.1 = [4 x i32] [i32 102, i32 111, i32 111, i32 0]
@.str.2 = [53 x i8] c"sprintf (buf, \22%.0ls\22, L\22foo\22) produced some output\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i64 @sprintf(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* bitcast ([4 x i32]* @.str.1 to i8*))
%6 = icmp ne i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7, %0
%12 = call i32 @puts(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %13
13: ; preds = %11, %7
%14 = load i32, i32* %3
ret i32 %14
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.0ls\00"
@.str.1 = [4 x i32] [i32 102, i32 111, i32 111, i32 0]
@.str.2 = [53 x i8] c"sprintf (buf, \22%.0ls\22, L\22foo\22) produced some output\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i64 @sprintf(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* bitcast ([4 x i32]* @.str.1 to i8*))
%4 = icmp eq i64 %3, 0
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
%7 = select i1 %4, i1 %6, i1 false
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ 1, %8 ], [ 0, %0 ]
ret i32 %11
}