#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 *);
scalar_t__ memchr(char *, char, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
char *strrchr(char *, char);
int main() {
  int num;
  char *dup, *c;
  char buf[8];
  dup = strdup("3");
  if (sscanf(dup, "%d", &num) > 0)
    printf("got %d\n", num);
  c = strrchr(dup, 'x');
  c = strchr(dup, 'x');
  c = (char *)memchr(dup, 'x', 2);
  buf[0] = '1';
  buf[1] = '\0';
  strcat(buf, dup);
  num = strlen(dup);
  free(dup);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
jle    11dc <main+0x4c>
mov    -0x8(%rbp),%esi
lea    0xe2e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x78,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x78,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x78,%esi
mov    $0x2,%edx
call   1080 <memchr@plt>
mov    %rax,-0x18(%rbp)
movb   $0x31,-0x20(%rbp)
movb   $0x0,-0x1f(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
lea    0xe77(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1070 <sscanf@plt>
test   %rax,%rax
jle    11ad <main+0x3d>
mov    0x4(%rsp),%esi
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x78,%esi
mov    $0x2,%edx
call   1060 <memchr@plt>
movw   $0x31,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"3\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"got %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [8 x i8]
store i32 0, i32* %1
%6 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %0
%14 = load i8*, i8** %3
%15 = call i8* @strrchr(i8* %14, i8 signext 120)
store i8* %15, i8** %4
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 120)
store i8* %17, i8** %4
%18 = load i8*, i8** %3
%19 = call i64 @memchr(i8* %18, i8 signext 120, i32 2)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %4
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
store i8 49, i8* %21
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
store i8 0, i8* %22
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %3
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %2
%28 = load i8*, i8** %3
%29 = call i32 @free(i8* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"3\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"got %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%5 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %0
%12 = call i64 @memchr(i8* %5, i8 signext 120, i32 2)
store i8 49, i8* %4
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 0, i8* %13
%14 = call i32 @strcat(i8* %4, i8* %5)
%15 = call i32 @strlen(i8* %5)
%16 = call i32 @free(i8* %5)
ret i32 0
}