#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strtok(char *, char *);
char *rewrite_url(char *url) {
  char *res;
  char *resultat;
  if ((res = strchr(url, '?')) != NULL) {
    resultat = strtok(url, "?");
    fprintf(stderr, "%s", resultat);
    return resultat;
  } else {
    fprintf(stderr, "%s", url);
    return url;
  }
}


x86 assembly (clang, -O0):
<rewrite_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1192 <rewrite_url+0x62>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <rewrite_url+0x83>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_url>:
push   %rbx
mov    %rdi,%rbx
mov    $0x3f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1155 <rewrite_url+0x25>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    %rax,%rbx
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"?\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i8* @rewrite_url(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 63)
store i8* %7, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %5
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %5
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %5
store i8* %15, i8** %2
br label %21
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %3
store i8* %20, i8** %2
br label %21
21: ; preds = %16, %9
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [2 x i8] c"?\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i8* @rewrite_url(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 63)
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %1, %4
%7 = phi i8* [ %5, %4 ], [ %0, %1 ]
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
ret i8* %7
}