#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 sprintf(char *, char *, char const *, ...);
scalar_t__ strlen(char const *);
int path_and_query_fill(char *buffer, const char *args[]) {
  const char *path = args[0];
  const char *query = args[1];
  if (query && strlen(query) > 0) {
    return sprintf(buffer, "%s?%s", path, query);
  } else {
    return sprintf(buffer, "%s", path);
  }
}


x86 assembly (clang, -O0):
<path_and_query_fill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1187 <path_and_query_fill+0x67>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    1187 <path_and_query_fill+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <path_and_query_fill+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_and_query_fill>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rsi),%r14
mov    0x8(%rsi),%rbx
test   %rbx,%rbx
je     116d <path_and_query_fill+0x3d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    116d <path_and_query_fill+0x3d>
lea    0xea8(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <stpcpy@plt>
sub    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s?%s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @path_and_query_fill(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
store i8* %10, i8** %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = call i64 @strlen(i8* %17)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
store i32 %24, i32* %3
br label %29
25: ; preds = %16, %2
%26 = load i8*, i8** %4
%27 = load i8*, i8** %6
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 %28, i32* %3
br label %29
29: ; preds = %25, %20
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s?%s\00"
define i32 @path_and_query_fill(i8* %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i64 @strlen(i8* %5)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %5)
br label %18
12: ; preds = %7, %2
%13 = tail call i8* @stpcpy(i8* %0, i8* %3)
%14 = ptrtoint i8* %13 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
br label %18
18: ; preds = %12, %10
%19 = phi i32 [ %11, %10 ], [ %17, %12 ]
ret i32 %19
}