#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 EOF;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int sscanf(char *, char *, ...);
int main(int arc, char *argv[]) {
  int n, res;
  unsigned int val;
  char s[] = "111";
  int result = 0;
  n = 0;
  res = sscanf(s, "%u %n", &val, &n);
  printf("Result of sscanf = %d\n", res);
  printf("Scanned format %%u = %u\n", val);
  printf("Possibly scanned format %%n = %d\n", n);
  result |= res != 1 || val != 111 || n != 3;
  result |= sscanf("", " %n", &n) == EOF;
  puts(result ? "Test failed" : "All tests passed");
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb4(%rip),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe9c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x25(%rbp)
jne    11cf <main+0x9f>
mov    $0x1,%al
cmpl   $0x6f,-0x1c(%rbp)
mov    %al,-0x25(%rbp)
jne    11cf <main+0x9f>
cmpl   $0x3,-0x14(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xe3c(%rip),%rdi
lea    0xe1b(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
lea    0xe51(%rip),%rdi
lea    0xe3e(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
call   1030 <puts@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x313131,0xc(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xeb1(%rip),%rsi
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%r14
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %eax,%ebp
lea    0xe95(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
xor    $0x1,%ebp
mov    0x8(%rsp),%eax
xor    $0x6f,%eax
or     %ebp,%eax
mov    0x4(%rsp),%ecx
xor    $0x3,%ecx
or     %eax,%ecx
setne  %bl
lea    0xe65(%rip),%rdi
lea    0xe44(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
or     %bl,%al
movzbl %al,%ebx
lea    0xe78(%rip),%rax
lea    0xe7d(%rip),%rdi
test   %bl,%bl
cmovne %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.s = [4 x i8] c"111\00"
@.str = [6 x i8] c"%u %n\00"
@.str.1 = [23 x i8] c"Result of sscanf = %d\0A\00"
@.str.2 = [25 x i8] c"Scanned format %%u = %u\0A\00"
@.str.3 = [34 x i8] c"Possibly scanned format %%n = %d\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [4 x i8] c" %n\00"
@EOF = global i32 0
@.str.6 = [12 x i8] c"Test failed\00"
@.str.7 = [17 x i8] c"All tests passed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [4 x i8]* %9 to i8*
store i32 0, i32* %10
store i32 0, i32* %6
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%13 = call i32 (i8*, i8*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %6)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 1
br i1 %21, label %28, label %22
22: ; preds = %2
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 111
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 3
br label %28
28: ; preds = %25, %22, %2
%29 = phi i1 [ true, %22 ], [ true, %2 ], [ %27, %25 ]
%30 = zext i1 %29 to i32
%31 = load i32, i32* %10
%32 = or i32 %31, %30
store i32 %32, i32* %10
%33 = call i32 (i8*, i8*, ...) @sscanf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
%36 = zext i1 %35 to i32
%37 = load i32, i32* %10
%38 = or i32 %37, %36
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0)
%43 = call i32 @puts(i8* %42)
%44 = load i32, i32* %10
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"%u %n\00"
@.str.1 = [23 x i8] c"Result of sscanf = %d\0A\00"
@.str.2 = [25 x i8] c"Scanned format %%u = %u\0A\00"
@.str.3 = [34 x i8] c"Possibly scanned format %%n = %d\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [4 x i8] c" %n\00"
@EOF = global i32 0
@.str.6 = [12 x i8] c"Test failed\00"
@.str.7 = [17 x i8] c"All tests passed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 3223857, i32* %5
store i32 0, i32* %3
%9 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %3)
%10 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = icmp ne i32 %9, 1
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 111
%18 = select i1 %15, i1 true, i1 %17
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 3
%21 = select i1 %18, i1 true, i1 %20
%22 = call i32 (i8*, i8*, ...) @sscanf(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
%25 = or i1 %21, %24
%26 = zext i1 %25 to i32
%27 = select i1 %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0)
%28 = call i32 @puts(i8* dereferenceable(1) %27)
ret i32 %26
}