#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*/ abort();
int /*<<< orphan*/ printf(char *, int);
int sscanf(char *, char *, unsigned int *, int *);
int main(int arc, char *argv[]) {
  int n, res;
  unsigned int val;
  char s[] = "111";
  val = n = -1;
  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);
  if (n != 3 || val != 111 || res != 1)
    abort();
  val = n = -1;
  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);
  if (n != 3 || val != 111 || res != 1)
    abort();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb4(%rip),%eax
mov    %eax,-0x20(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe9c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x3,-0x14(%rbp)
jne    11c3 <main+0x93>
cmpl   $0x6f,-0x1c(%rbp)
jne    11c3 <main+0x93>
cmpl   $0x1,-0x18(%rbp)
je     11ca <main+0x9a>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x3,-0x14(%rbp)
jne    123e <main+0x10e>
cmpl   $0x6f,-0x1c(%rbp)
jne    123e <main+0x10e>
cmpl   $0x1,-0x18(%rbp)
je     1245 <main+0x115>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x313131,0xc(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xeac(%rip),%rsi
lea    0xc(%rsp),%rdi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1050 <sscanf@plt>
mov    %eax,%ebx
lea    0xe95(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x1,%ebx
jne    1225 <main+0xf5>
cmpl   $0x3,0x8(%rsp)
jne    1225 <main+0xf5>
cmpl   $0x6f,0x4(%rsp)
jne    1225 <main+0xf5>
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xe92(%rip),%rsi
lea    0xc(%rsp),%rdi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1050 <sscanf@plt>
mov    %eax,%ebx
lea    0xe23(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x1,%ebx
jne    1225 <main+0xf5>
cmpl   $0x3,0x8(%rsp)
jne    1225 <main+0xf5>
cmpl   $0x6f,0x4(%rsp)
jne    1225 <main+0xf5>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

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 = [5 x i8] c"%u%n\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]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [4 x i8]* %9 to i8*
store i32 -1, i32* %6
store i32 -1, i32* %8
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %6)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %8
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 3
br i1 %20, label %27, label %21
21: ; preds = %2
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 111
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %24, %21, %2
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %24
store i32 -1, i32* %6
store i32 -1, i32* %8
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%31 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %8, i32* %6)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %8
%35 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %6
%37 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 3
br i1 %39, label %46, label %40
40: ; preds = %29
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 111
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %43, %40, %29
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %43
ret i32 0
}

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 = [5 x i8] c"%u%n\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 -1, i32* %3
store i32 -1, i32* %4
%9 = call i32 @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 = load i32, i32* %3
%16 = icmp ne i32 %15, 3
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 111
%19 = select i1 %16, i1 true, i1 %18
%20 = icmp ne i32 %9, 1
%21 = or i1 %20, %19
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %2
store i32 -1, i32* %3
store i32 -1, i32* %4
%25 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %3)
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = icmp ne i32 %31, 3
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 111
%35 = select i1 %32, i1 true, i1 %34
%36 = icmp ne i32 %25, 1
%37 = or i1 %36, %35
br i1 %37, label %38, label %40
38: ; preds = %24
%39 = call i32 (...) @abort()
unreachable
40: ; preds = %24
ret i32 0
}