#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*/ free(char *);
int /*<<< orphan*/ sscanf(char const *, char *, ...);
scalar_t__ strcmp(char *, char *);
int main(void) {
  const char *buf = "hello world";
  char *ps = NULL, *pc = NULL;
  char s[6], c;
  sscanf(buf, "%[a-z] %c", s, &c);
  sscanf(buf, "%m[a-z] %mc", &ps, &pc);
  if (strcmp(ps, "hello") != 0 || *pc != 'w' || strcmp(s, "hello") != 0 ||
      c != 'w')
    return 1;
  free(ps);
  free(pc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x26(%rbp),%rdx
lea    0xea3(%rip),%rsi
lea    -0x27(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11df <main+0xaf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x77,%eax
jne    11df <main+0xaf>
lea    -0x26(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11df <main+0xaf>
movsbl -0x27(%rbp),%eax
cmp    $0x77,%eax
je     11eb <main+0xbb>
movl   $0x1,-0x4(%rbp)
jmp    1204 <main+0xd4>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xeb2(%rip),%rbx
lea    0xeb7(%rip),%rsi
lea    0x1a(%rsp),%rdx
lea    0x7(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
lea    0xea6(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0x10(%rsp),%rdi
lea    0xe92(%rip),%rsi
call   1040 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    11dc <main+0xac>
mov    0x8(%rsp),%rax
cmpb   $0x77,(%rax)
jne    11dc <main+0xac>
lea    0xe72(%rip),%rsi
lea    0x1a(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11dc <main+0xac>
cmpb   $0x77,0x7(%rsp)
jne    11dc <main+0xac>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [10 x i8] c"%[a-z] %c\00"
@.str.2 = [12 x i8] c"%m[a-z] %mc\00"
@.str.3 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [6 x i8]
%6 = alloca i8
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* null, i8** %3
store i8* null, i8** %4
%7 = load i8*, i8** %2
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%9 = call i32 (i8*, i8*, ...) @sscanf(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %6)
%10 = load i8*, i8** %2
%11 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %3, i8** %4)
%12 = load i8*, i8** %3
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %0
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 119
br i1 %19, label %28, label %20
20: ; preds = %15
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 119
br i1 %27, label %28, label %29
28: ; preds = %24, %20, %15, %0
store i32 1, i32* %1
br label %34
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %29, %28
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [10 x i8] c"%[a-z] %c\00"
@.str.2 = [12 x i8] c"%m[a-z] %mc\00"
@.str.3 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [6 x i8]
%4 = alloca i8
%5 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%6 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%8 = call i32 (i8*, i8*, ...) @sscanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %4)
%9 = call i32 (i8*, i8*, ...) @sscanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %1, i8** %2)
%10 = load i8*, i8** %1
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 119
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
%20 = load i8, i8* %4
%21 = icmp ne i8 %20, 119
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = load i8*, i8** %1
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %2
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %0, %13, %17, %23
%29 = phi i32 [ 0, %23 ], [ 1, %17 ], [ 1, %13 ], [ 1, %0 ]
ret i32 %29
}