#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*/ printf(char *, ...);
int sscanf(char *, char *, int *, char *);
int main(int argc, const char *argv[]) {
  int m, iv;
  char c;
  iv = -999;
  c = '\0';
  m = sscanf("xx", "%d%c", &iv, &c);
  if (m != 0)
    printf("Error in sscanf: %s ->  m=%d, iv=%d, c=%c\n", "xx", m, iv, c);
  else
    printf("sscanf OK\n");
  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)
movl   $0xfffffc19,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
lea    0xeb8(%rip),%rdi
lea    0xeb4(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x19(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <main+0x6e>
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsbl -0x19(%rbp),%r8d
lea    0xe8d(%rip),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119c <main+0x7c>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0xfffffc19,0x4(%rsp)
ff
movb   $0x0,0x3(%rsp)
lea    0xebb(%rip),%rdi
lea    0xeb7(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1050 <sscanf@plt>
test   %eax,%eax
je     1182 <main+0x52>
mov    0x4(%rsp),%ecx
movsbl 0x3(%rsp),%r8d
lea    0xe98(%rip),%rdi
lea    0xe89(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118e <main+0x5e>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"xx\00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [43 x i8] c"Error in sscanf: %s -> m=%d, iv=%d, c=%c\0A\00"
@.str.3 = [11 x i8] c"sscanf OK\0A\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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -999, i32* %7
store i8 0, i8* %8
%9 = call i32 @sscanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %7, i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = load i8, i8* %8
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i32 %16)
br label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"xx\00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [43 x i8] c"Error in sscanf: %s -> m=%d, iv=%d, c=%c\0A\00"
@str = [10 x i8] c"sscanf OK\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
store i32 -999, i32* %3
store i8 0, i8* %4
%6 = call i32 @sscanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9, i32 %11)
br label %15
13: ; preds = %2
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
ret i32 0
}